File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #include " gmod.h"
1+ extern " C"
2+ {
3+ #include " gmod.h"
4+ #include " lua.h"
5+ }
6+ #include " stdio.h"
27
38namespace 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+
208224extern " 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 );
Original file line number Diff line number Diff 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 (75 a06 ,98042110 ) >> 4 * t ) & 15u );
239+ int tt = (int )((U64x (75 a06 ,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
245247LUALIB_API void luaL_checktype (lua_State * L , int idx , int tt )
You can’t perform that action at this time.
0 commit comments