lua-users home
lua-l archive

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


Hans van der Meer wrote:
> I am having a strange experience with "luaL_newmetable" and friends.
> 
> 1=> I get bus errors when in the B-module I ask for luaL_newmetatable(L,
> "a-id") in stead of "b-id".
> 
> 2=> Calling luaL_newmetatable with a non-existing key "c-id" instead
> does not raise the error.
> 
> 3=> I get bus errors when accessing the stack in B ("a-id" in the
> entrance code) after lines:
>      mytype *m = lua_newuserdata(L, sizeof(mytype));
>     /* Mark userdata as file structure data, remove from the stack. */
>     luaL_getmetatable(L, "b-id");
>     lua_setmetatable(L, -2);
> 
> I suspect the problem has something to do with accessing the registry
> for an existing table. But why? The reference manual clearly states
> (page 61) "If the registry already has the key tname ..... In both cases
> pushes onto the stack the final value associated with tname in the
> registry."
> 
I can't see anything obviously wrong with that code snippet, but 90% of
the time, when you get segfaults, bus errors, or other crashes in the
lua API it's because you're misusing it. Try recompiling lua with
LUA_USE_APICHECK defined - this will add checks to lua that will cause
it to assert() on programmer error.
If after doing this you still see bus errors, try constructing a minimal
code example that replicates this behaviour, and posting it to the list
or pastebinning it for others to dissect.
	Ben