lua-users home
lua-l archive

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


> 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