lj_obj.c 1.3 KB

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