It would be useful to have to allow for encoding of more complex data structures, also to allow tables that have functions to be encoded by specifying them to not be included
Probably best for
__tojson
to return what we want to be encoded rather than actual json?
local Nested = {}
Nested.__index = Nested
function Nested:__tojson()
return {
name= self.name,
child= if self.child then self.child else nil
}
end
function Nested.new(name,parent)
return setmetatable({
name=name,
parent=parent,
child=nil
},Nested)
end
local root = Nested.new("root")
root.child = Nested.new("child1",root)
root.child.child = Nested.new("child2",root.child)
ll.OwnerSay(lljson.encode(root))
Possibly this is deemed too much of an addition as it can be achieved atm with this
local Nested = {}
Nested.__index = Nested
function Nested:__tojson()
return {
name= self.name,
child= if self.child then self.child:__tojson() else nil
}
end
function Nested.new(name,parent)
return setmetatable({
name=name,
parent=parent,
child=nil
},Nested)
end
local root = Nested.new("root")
root.child = Nested.new("child1",root)
root.child.child = Nested.new("child2",root.child)
ll.OwnerSay(lljson.encode(root:__tojson()))