|
Doug Rogers wrote: (...)
int l_event_new(lua_State* L, const char* event_name) { lua_newtable(L); // local obj = {} luaL_getmetatable(L, "Event.mt"); // setmetatable(obj, mt) lua_setmetatable(L, -2); lua_pushstring(L, event_name); // obj.name = event_name lua_settable(L, -2, "name"); return 1; // return obj }
Shouldn't it be something like... int l_event_new( lua_State* L ) { luaL_checkstr(L, 1); lua_newtable(L); // local obj = {} luaL_getmetatable(L, "Event.mt"); // setmetatable(obj, mt) lua_setmetatable(L, -2); lua_pushvalue(L, 1); // obj.name = event_name lua_settable(L, -2, "name"); return 1; // return obj } ? --rb