src/lj_obj.c - luajit-2.0-src

Global variables defined

Functions defined

Macros defined

Source code

  1. /*
  2. ** Miscellaneous object handling.
  3. ** Copyright (C) 2005-2015 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(cTValue *o)
  32. {
  33.   if (tvisudata(o))
  34.     return uddata(udataV(o));
  35.   else if (tvislightud(o))
  36.     return lightudV(o);
  37.   else if (LJ_HASFFI && tviscdata(o))
  38.     return cdataptr(cdataV(o));
  39.   else if (tvisgcv(o))
  40.     return gcV(o);
  41.   else
  42.     return NULL;
  43. }