lua-users home
lua-l archive

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


Doug Rogers wrote:
Matthew Metnetsky wrote:
    lua_rawgeti(L, LUA_REGISTRYINDEX, class);
    g_assert(lua_type(L, -1) == LUA_TTABLE);
    lua_getfield(L, -1, cmd);
    g_assert(lua_type(L, -1) == LUA_TFUNCTION);
    lua_pushstring(L, args);
    g_assert(lua_type(L, -1) == LUA_TSTRING);
    if (0 != lua_pcall(L, 1, 1, 0)) { // pass 1 argument, get 1 value...

What Peter wrote, plus a copy of the 'class' object, assuming that's what you want (untested):

    lua_rawgeti(L, LUA_REGISTRYINDEX, class);
    g_assert(lua_type(L, -1) == LUA_TTABLE);
    lua_getfield(L, -1, cmd);
    g_assert(lua_type(L, -1) == LUA_TFUNCTION);
    lua_pushvalue(L, -2);      // Copy 'class' object.
    lua_pushstring(L, args);
    g_assert(lua_type(L, -1) == LUA_TSTRING);
    if (0 != lua_pcall(L, 2, 1, 0)) { // pass 2 args, get 1 value...

Doug