2626#include "lj_strscan.h"
2727#include "lj_strfmt.h"
2828
29- #include "lj_ctype.h"
30- #include "lj_cconv.h"
31-
3229/* -- Common helper functions --------------------------------------------- */
3330
3431#define lj_checkapi_slot (idx ) \
@@ -233,18 +230,16 @@ LUA_API int lua_type(lua_State *L, int idx)
233230#endif
234231 } else if (o == niltv (L )) {
235232 return LUA_TNONE ;
236- } else if (tviscdata (o )) {
237- return LUA_TUSERDATA ; // we would return 10 which conflicts with gmod!
238- } /* Magic internal/external tag conversion. ORDER LJ_T */
239-
240- uint32_t t = ~itype (o );
233+ } else { /* Magic internal/external tag conversion. ORDER LJ_T */
234+ uint32_t t = ~itype (o );
241235#if LJ_64
242- int tt = (int )((U64x (75 a06 ,98042110 ) >> 4 * t ) & 15u );
236+ int tt = (int )((U64x (75 a06 ,98042110 ) >> 4 * t ) & 15u );
243237#else
244- int tt = (int )(((t < 8 ? 0x98042110u : 0x75a06u ) >> 4 * (t & 7 )) & 15u );
238+ int tt = (int )(((t < 8 ? 0x98042110u : 0x75a06u ) >> 4 * (t & 7 )) & 15u );
245239#endif
246- lj_assertL (tt != LUA_TNIL || tvisnil (o ), "bad tag conversion" );
247- return tt ;
240+ lj_assertL (tt != LUA_TNIL || tvisnil (o ), "bad tag conversion" );
241+ return tt ;
242+ }
248243}
249244
250245LUALIB_API void luaL_checktype (lua_State * L , int idx , int tt )
@@ -262,37 +257,25 @@ LUALIB_API void luaL_checkany(lua_State *L, int idx)
262257// Based off https://github.com/meepen/gluajit/blob/master/src/lj_api.c#L225-L247
263258/*extern "C"*/ const char * GMODLUA_GetUserType (lua_State * L , int iStackPos )
264259{
265- static char strName [128 ];
266- const char * strTypeName = "UserData" ;
267- cTValue * o = index2adr (L , iStackPos );
268- GCtab * mt = NULL ;
269- if (tvistab (o ))
270- mt = tabref (tabV (o )-> metatable );
271- else if (tvisudata (o ))
272- mt = tabref (udataV (o )-> metatable );
273- else if (tviscdata (o ))
274- {
275- strTypeName = "cdata" ;
276- CTState * cts = ctype_cts (L );
277- CType * ct = ctype_raw (cts , cdataV (o )-> ctypeid );
278- mt = tabV (lj_tab_getinth (cts -> miscmap , - (int32_t )ctype_typeid (cts , ct )));
279- } else
280- mt = tabref (basemt_obj (G (L ), o ));
260+ static char strName [128 ];
261+ const char * strTypeName = "UserData" ;
262+ if (lua_getmetatable (L , iStackPos ))
263+ {
264+ lua_pushstring (L , "MetaName" );
265+ lua_gettable (L , -2 );
281266
282- if (mt )
283- {
284- GCstr * str = lj_str_newlit (L , "MetaName" );
285- cTValue * val = lj_tab_getstr ( mt , str ) ;
286- // lj_str_free(G(L), str); // Lua GC takes care of our string
267+ if (lua_isstring ( L , -1 ) )
268+ {
269+ strncpy ( strName , lua_tostring (L , -1 ), sizeof ( strName ) );
270+ strTypeName = strName ;
271+ }
287272
288- if (val && tvisstr (val ))
289- {
290- strncpy (strName , strdata (strV (val )), sizeof (strName ));
291- strTypeName = strName ;
292- }
293- }
273+ lua_pop (L , 1 );
274+ }
275+
276+ lua_pop (L , 1 );
294277
295- return strTypeName ;
278+ return strTypeName ;
296279}
297280
298281LUA_API const char * lua_typename (lua_State * L , int t , int stackpos )
0 commit comments