lua-users home
lua-l archive

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

Sivan Thiruvengadam wrote:
Thanks. Let me change this by pushing the object as you suggest and see if things work as expected. BTW, I always hit the else part of the CLNumList constructor, since i am not passing any CLNumList instance from LUA.

Yep, I forgot that Lunar removes 'self'.

// member function dispatcher
static int thunk(lua_State *L) {
  // stack has userdata, followed by method args
  T *obj = check(L, 1);  // get 'self', or if you prefer, 'this'
---> lua_remove(L, 1); // remove self so member function args start at index 1
  // get member function from upvalue
RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));
  return (obj->*(l->mfunc))(L);  // call member function