Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Lua Json
Commits
f515814f
Commit
f515814f
authored
May 11, 2019
by
seny
Browse files
Fix docs
parent
3389b0d2
Changes
1
Show whitespace changes
Inline
Side-by-side
README.md
View file @
f515814f
...
@@ -108,11 +108,11 @@ local mt = {
...
@@ -108,11 +108,11 @@ local mt = {
__toB = function (t) return {B = t.b} end, -- [b -> B]
__toB = function (t) return {B = t.b} end, -- [b -> B]
}
}
local function
construct
(t) return setmetatable(t, mt) end
local function
new
(t) return setmetatable(t, mt) end
local function fromA(t) return
construct
{a = t.A} end -- [A -> a]
local function fromA(t) return
new
{a = t.A} end -- [A -> a]
local function fromB(t) return
construct
{b = t.B} end -- [B -> b]
local function fromB(t) return
new
{b = t.B} end -- [B -> b]
local obj =
construct
{a = 'a', b = 'b'}
local obj =
new
{a = 'a', b = 'b'}
assert(tostring(obj) == 'ab')
assert(tostring(obj) == 'ab')
assert(tostring(encode_decode(obj, '__toA', fromA)) == 'a')
assert(tostring(encode_decode(obj, '__toA', fromA)) == 'a')
assert(tostring(encode_decode(obj, '__toB', fromB)) == 'b')
assert(tostring(encode_decode(obj, '__toB', fromB)) == 'b')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment