lua-users home
lua-l archive

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


Hi,

Rici Lake wrote:
> By the way, the largest possible Lua stack frame is 255 slots. 
> (LUA_MAXSTACK + LUA_EXTRA_STACK, but don't change these!)

255 is just the limit for the directly addressable slots
(aka local variables). A Lua function will happily pass
on any number for open operations (return f(), g(f()),
{f()}, return ..., f(...), {...}).

Examples (Lua 5.1 required):

$ lua -e 'print(string.byte(string.rep("\0", 1000), 1, -1))'
$ lua -e 'print(#{string.byte(string.rep("\0", 1000), 1, -1)})'

[The limit here is LUAI_MAXCSTACK (2048).]

But we can do better:

  local function foo(n, ...)
    if n == 0 then return ... else return foo(n-1, 0, ...) end
  end

  print(#{foo(30000)})

[This will take a long time.]

And unless I'm mistaken there is no relationship between
MAXSTACK and EXTRA_STACK. Only MAXSTACK has to be <= MAXARG_A
(255). EXTRA_STACK is used for easier calling of metamethods.
There are no arithmetics involved that would truncate the
sum of those two to 8 bits.

Please correct me if I'm wrong, because I increased EXTRA_STACK
(for a good, but complicated to explain reason).

Bye,
     Mike