lj_obj.c (1309B)
1 /* 2 ** Miscellaneous object handling. 3 ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h 4 */ 5 6 #define lj_obj_c 7 #define LUA_CORE 8 9 #include "lj_obj.h" 10 11 /* Object type names. */ 12 LJ_DATADEF const char *const lj_obj_typename[] = { /* ORDER LUA_T */ 13 "no value", "nil", "boolean", "userdata", "number", "string", 14 "table", "function", "userdata", "thread", "proto", "cdata" 15 }; 16 17 LJ_DATADEF const char *const lj_obj_itypename[] = { /* ORDER LJ_T */ 18 "nil", "boolean", "boolean", "userdata", "string", "upval", "thread", 19 "proto", "function", "trace", "cdata", "table", "userdata", "number" 20 }; 21 22 /* Compare two objects without calling metamethods. */ 23 int LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2) 24 { 25 if (itype(o1) == itype(o2)) { 26 if (tvispri(o1)) 27 return 1; 28 if (!tvisnum(o1)) 29 return gcrefeq(o1->gcr, o2->gcr); 30 } else if (!tvisnumber(o1) || !tvisnumber(o2)) { 31 return 0; 32 } 33 return numberVnum(o1) == numberVnum(o2); 34 } 35 36 /* Return pointer to object or its object data. */ 37 const void * LJ_FASTCALL lj_obj_ptr(cTValue *o) 38 { 39 if (tvisudata(o)) 40 return uddata(udataV(o)); 41 else if (tvislightud(o)) 42 return lightudV(o); 43 else if (LJ_HASFFI && tviscdata(o)) 44 return cdataptr(cdataV(o)); 45 else if (tvisgcv(o)) 46 return gcV(o); 47 else 48 return NULL; 49 } 50