[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: luaL_register crashed on iOS
- From: 曹煦 <cao.xu@...>
- Date: Thu, 17 Sep 2015 22:24:04 +0800
Sorry for the misleading conclusion.
The truth is that the broken code still crash under 5.1.5. However，it happened to work fine after I inserted some lua_checkstack() calls before those luaL_register(), which only work fine with lua5.1.5 (the code still crash under 5.1.4). So I simply thought it’s caused by the lua version.
Thanks for the explanation.
> 在 2015年9月17日，下午9:46，Roberto Ierusalimschy <firstname.lastname@example.org> 写道：
>> 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'  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 :
> 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.
>  http://www.lua.org/manual/5.1/manual.html#luaL_register
>  http://www.lua.org/manual/5.1/manual.html#3.2
> -- Roberto