lua-users home
lua-l archive

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


Romulo Bahiense wrote:
> 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
> }

You're right. In addition to adding the checks above, Shea, you will
need to get the name from the Lua stack if this is being called from Lua
directly (as it was in my example code). If you are creating the value
from C code, though, you would pass the name in as a const char* then
push it on the stack.

Doug

-- 
Innovative Concepts, Inc. www.innocon.com 703-893-2007 x220