[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luaL_register crashed on iOS
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 17 Sep 2015 10:46:35 -0300
> It seems like a bug of luaV_settable of version 5.1.4, and works fine under 5.1.5
As lhf said, your code is broken; you should fix it even if it works
under 5.1.5.
The documentation of 'luaL_register' [1] is clear:
When called with a non-null libname, luaL_register creates a new table t,
[...]
In any case the function leaves the table on the top of the stack.
So, you push one new element on the stack at each call to
'luaL_register'. The documentation also says [2]:
When you interact with Lua API, you are responsible for ensuring
consistency. In particular, you are responsible for controlling
stack overflow. [...]
Whenever Lua calls C, it ensures that at least LUA_MINSTACK stack
positions are available. LUA_MINSTACK is defined as 20, [...]
As you call 'luaL_register' more than 20 times without popping the
results, you have a stack overflow. Anything that happens after that
is undefined behavior (which means it can even work as expected).
If your corrected code still crashes under 5.1.4, please tell us.
[1] http://www.lua.org/manual/5.1/manual.html#luaL_register
[2] http://www.lua.org/manual/5.1/manual.html#3.2
-- Roberto