lj_obj.c 956 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. ** Miscellaneous object handling.
  3. ** Copyright (C) 2005-2014 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_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. }