lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Tim Hill once stated:
> 
> >> 
> >> I would doubt that using varargs as a Forth stack is the best approach. What’s wrong with a Lua array (aka table)?
> > Lua arrays can't do nil, Lua stacks can.
> 
> Well, it’s true that a “true” Lua array (a sequence) cannot contain a nil value, but if you maintain your own top-of-stack (aka array size), then there is no reason why you cannot have nil as the value of some elements…
> 
> t = { “a”, “b”, “c” }
> t.len = 3
> t[2] = nil

  And in Lua 5.2:

t = setmetatable(
	{ _len = 3 },
	{ __len = function(self) return self._len end }
)

print(#t)

  -spc