[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_next() crashing on former LUA_TNONE arguments
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 13 Dec 2017 10:43:50 -0200
> I have this code:
>
> int foo(lua_State *L)
> {
> lua_checkstack(L, 10);
> lua_pushvalue(L, 1);
> lua_pushnil(L);
> lua_next(L, -2);
> return 0;
> }
>
> void bar()
> {
> lua_State* L = luaL_newstate();
> lua_pushcfunction(L, foo);
> lua_setglobal(L, "foo");
> luaL_dostring(L, "foo()");
> }
>
> When I call bar(), it crashes within a call to lua_next, within the code
> generated for line
>
> more = luaH_next(L, hvalue(t), L->top - 1);
>
> in lapi.c.
>
> There is no crash when I modify the last line in bar() to read
> luaL_dostring(L, "foo()").
>
> This happens with Lua 5.3.3.
>
> [...]
>
> What am I missing?
'lua_next' works only with tables. Both cases are wrong. You can
compile Lua with LUA_USE_APICHECK on (see 'luaconf.h') to detect
that kind of error in API calls.
-- Roberto