[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: bus error on metatable
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Sun, 3 Aug 2008 20:19:48 +0200
2008/8/3 Hans van der Meer <H.vanderMeer@uva.nl>:
> I am having a strange experience with "luaL_newmetable" and friends.
> Having two modules A and B. Module B is called through A. In both modules
> the entrance code is:
> int luaopen_a (lua_State *L) { /* resp. luaopen_b */
> /* Set new table for shared C-function environment. */
> lua_newtable(L); /* removal of these two */
> lua_replace(L, LUA_ENVIRONINDEX); /* made no difference */
> /* Make metatable for filehandle userdata. */
> fprintf(stderr,"stacktop at %d before\n",lua_gettop(L));
> luaL_newmetatable(L, "a-id"); /* resp. "b-id" */
> fprintf(stderr,"stacktop at %d after\n",lua_gettop(L));
> /* Add __tostring function. */
> lua_pushcfunction(L, iom_tostring);
> lua_setfield(L, -2, "__tostring");
> etc.
> 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 am at my wits end. Any pointers to the culprit will be appreciated. Thanks
> in advance.
Can you provide the full code (both C and Lua) of a minimal example
showing the problem ?