X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flib%2Fserialize.lua;h=505291826f558a728e2dca0c87901f2cb00d1505;hb=9d86c221fb53ba31f15d333e56513b8bfff2cefa;hp=7bbe092ab793f2d26fbce055024ef035b34734dc;hpb=4c54e64f4b7d1d539006274fcee522643a70202e;p=metalua.git diff --git a/src/lib/serialize.lua b/src/lib/serialize.lua index 7bbe092..5052918 100644 --- a/src/lib/serialize.lua +++ b/src/lib/serialize.lua @@ -4,11 +4,11 @@ -- to the original one. The following are currently supported: -- * strings, numbers, booleans, nil -- * functions without upvalues --- * tables thereof. Tables cna have shared part, but can't be recursive yet. +-- * tables thereof. Tables can have shared part, but can't be recursive yet. -- Caveat: metatables and environments aren't saved. -------------------------------------------------------------------------------- -local no_identity = table.transpose { 'number', 'boolean', 'string', 'nil' } +local no_identity = { number=1, boolean=1, string=1, nil=1 } function serialize (x) @@ -33,7 +33,8 @@ function serialize (x) if type (x) == 'table' then nested [x] = true for k, v in pairs (x) do - if nested [k] then error "Can't serialize recursive tables yet" end + if nested [k] or nexted [v] + then error "Can't serialize recursive tables yet" end mark_multiple_occurences (k) mark_multiple_occurences (v) end