Skip to content

Commit 33f0778

Browse files
committed
luajit: get cdata to not conflict with gmod's vector type
1 parent ee1d7b7 commit 33f0778

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

LuaJIT-2.1/src/gmod.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#include "gmod.h"
1+
extern "C"
2+
{
3+
#include "gmod.h"
4+
#include "lua.h"
5+
}
6+
#include "stdio.h"
27

38
namespace std
49
{
@@ -200,18 +205,37 @@ extern "C" void lua_init_stack_gmod(lua_State* L1, lua_State* L)
200205
}
201206
}
202207

203-
extern "C" void GMOD_LuaPrint(const char* str, lua_State* L) // Idk how gmod does it
208+
extern "C" void GMOD_LuaPrint(const char* str, lua_State* L) // Should be how gmod does it
204209
{
210+
if (!L->luabase) // except for this, gmod doesn't do this, but we do making testing jit less of a pain
211+
{
212+
printf(str);
213+
return;
214+
}
215+
205216
((ILuaInterface*)L->luabase)->Msg("%s", str);
206217
}
207218

219+
struct UserData {
220+
void* data;
221+
unsigned char type;
222+
};
223+
208224
extern "C" void GMOD_LuaCreateEmptyUserdata(lua_State* L)
209225
{
210226
//ILuaBase::UserData* udata = (ILuaBase::UserData*)((ILuaBase*)L->luabase)->NewUserdata(sizeof(ILuaBase::UserData)); // Gmod uses CLuaInterface::PushUserType(NULL, 7) Instead
211227
//udata->data = nullptr;
212228
//udata->type = 7; // 7 = Userdata
213229

214230
//return udata;
231+
232+
if (!L->luabase) // just to make testing easier. Gmod doesn't have this.
233+
{
234+
UserData* pData = (UserData*)lua_newuserdata(L, sizeof(ILuaBase::UserData));
235+
pData->data = nullptr;
236+
pData->type = 7;
237+
return;
238+
}
215239

216240

217241
((ILuaBase*)L->luabase)->PushUserType(NULL, 7);

LuaJIT-2.1/src/lj_api.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,18 @@ LUA_API int lua_type(lua_State *L, int idx)
230230
#endif
231231
} else if (o == niltv(L)) {
232232
return LUA_TNONE;
233-
} else { /* Magic internal/external tag conversion. ORDER LJ_T */
234-
uint32_t t = ~itype(o);
233+
} else if(tviscdata(o)) {
234+
return LUA_TUSERDATA; // we would return 10 which conflicts with gmod!
235+
} /* Magic internal/external tag conversion. ORDER LJ_T */
236+
237+
uint32_t t = ~itype(o);
235238
#if LJ_64
236-
int tt = (int)((U64x(75a06,98042110) >> 4*t) & 15u);
239+
int tt = (int)((U64x(75a06,98042110) >> 4*t) & 15u);
237240
#else
238-
int tt = (int)(((t < 8 ? 0x98042110u : 0x75a06u) >> 4*(t&7)) & 15u);
241+
int tt = (int)(((t < 8 ? 0x98042110u : 0x75a06u) >> 4*(t&7)) & 15u);
239242
#endif
240-
lj_assertL(tt != LUA_TNIL || tvisnil(o), "bad tag conversion");
241-
return tt;
242-
}
243+
lj_assertL(tt != LUA_TNIL || tvisnil(o), "bad tag conversion");
244+
return tt;
243245
}
244246

245247
LUALIB_API void luaL_checktype(lua_State *L, int idx, int tt)

0 commit comments

Comments
 (0)