[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Nested table constructor with reference to other children
- From: Philipp Janda <siffiejoe@...>
- Date: Sun, 30 Oct 2011 16:49:28 +0100
Oops, missing return.
On 30.10.2011 16:07, Philipp Janda wrote:
$ cat > ref.lua
local temp = {}
local function v( s )
return function( t )
temp[ s ] = t
return t
end
end
Mmmh, if you only need references to subtables, you could do even better ...
$ cat > ref2.lua
local temp = {}
local function v( s )
return function( t )
if temp[ s ] then
for k,v in pairs( t ) do
temp[ s ][ k ] = v
end
else
temp[ s ] = t
end
return temp[ s ]
end
end
local function r( s )
if not temp[ s ] then
temp[ s ] = {}
end
return temp[ s ]
end
a = {
one = v"one"{
a = 1,
b = r"two"
},
two = v"two"{
a = 1,
b = r"one"
}
}
print( a.two.b.b.b.b.b.b.a )
^D
Philipp (<- having a look at his old serializer/pretty-printer)