feat: add serializeArrays option (#29)

* feat: add optional `convertArrays`

* perf: sync atomic changes to keys

* feat: add `serializeArrays` option

* docs: rephrase debug mode flag
This commit is contained in:
richard 2024-11-17 01:22:07 -08:00 • committed by GitHub
parent e4019c049c
commit aae769c981
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 230 additions and 205 deletions

View file

@ -1,9 +1,7 @@
local Charm = require(script.Parent.Parent.Charm)
local SAFE_KEYS = { string = true, number = true }
local SAFE_VALUES = { string = true, number = true, boolean = true, table = true, userdata = true }
local SAFE_VALUES = { string = true, number = true, boolean = true, table = true, userdata = true, vector = true }
local function isUnsafeTable(object: { [any]: any })
local function isTableUnsafe(object: { [any]: any })
local keyType = nil
local objectSize = 0
@ -47,9 +45,7 @@ local function validate(value: any, key: any)
elseif typeOfValue == "table" then
if getmetatable(value) ~= nil then
error(`Cannot sync tables with metatables! Got {value} at key '{key}'`)
elseif Charm.isAtom(value) then
error(`Cannot sync nested atoms! Got atom at key '{key}'`)
elseif isUnsafeTable(value) then
elseif isTableUnsafe(value) then
error(
`Cannot sync tables unsupported by remote events! The value has the key '{key}'.\n\n`
.. "This can be for the following reasons:\n"
@ -69,7 +65,7 @@ local function validate(value: any, key: any)
elseif typeOfKey == "number" then
if key == math.huge or key == -math.huge then
error("Cannot sync infinity as key")
elseif math.floor(key) ~= key then
elseif key ~= math.floor(key) then
error("Cannot sync non-integer number as key")
end
end