From d56510b1ac5ef46264c454a43d8e7088baba05a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 25 Oct 2023 15:25:54 +0200 Subject: [PATCH] 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. --- src/lua/LuaLuna.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua/LuaLuna.h b/src/lua/LuaLuna.h index 9a7ec13be..b1f0d654f 100644 --- a/src/lua/LuaLuna.h +++ b/src/lua/LuaLuna.h @@ -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(lua_touserdata(L, lua_upvalueindex(1))); + RegType *l = T::methods + lua_tointeger(L, lua_upvalueindex(1)); return (obj->*(l->mfunc))(L); // call member function }