lua-users home
lua-l archive

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


Shmuel Zeigerman wrote:
You probably forgot to assign the "__index" field
of the metatable to the metatable itself:

  luaL_newmetatable(L, "LuaBook.gc_event");
  lua_pushliteral(L, "__index");
  lua_pushvalue(L, -2);         /* push metatable */
  lua_rawset(L, -3);            /* metatable.__index = metatable */

That is necessary only if you plan to use metatable as a place where Lua will look _userdata_ fields. It is a common (yet newbie-confusing) practice to store methods in metatable, instead of special separate table.

--
e.v.e