Use method indices as LuaLuna thunk upvalues

Rather than member function pointers, which are not necessarily simple pointers and are not necessarily convertible to void * sensibly. This also gets rid of the last instance of lua_pushlightuserdata, which apparently isn't super well-supported by luajit, and which thus often crash on android.
This commit is contained in:
Tamás Bálint Misius 2023-10-25 15:25:54 +02:00
parent b5d40a49f8
commit d56510b1ac
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -57,7 +57,7 @@ public:
{
/* edited by Snaily: shouldn't it be const RegType *l ... ? */
lua_pushstring(L, l->name);
lua_pushlightuserdata(L, (void*)l);
lua_pushinteger(L, l - T::methods);
lua_pushcclosure(L, thunk, 1);
lua_settable(L, methods);
}
@ -116,7 +116,7 @@ private:
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)));
RegType *l = T::methods + lua_tointeger(L, lua_upvalueindex(1));
return (obj->*(l->mfunc))(L); // call member function
}