2009-12-08 18:46:35 +00:00
|
|
|
/*
|
|
|
|
** Miscellaneous object handling.
|
2023-08-20 19:25:30 +00:00
|
|
|
** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
|
2009-12-08 18:46:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define lj_obj_c
|
|
|
|
#define LUA_CORE
|
|
|
|
|
|
|
|
#include "lj_obj.h"
|
|
|
|
|
|
|
|
/* Object type names. */
|
|
|
|
LJ_DATADEF const char *const lj_obj_typename[] = { /* ORDER LUA_T */
|
|
|
|
"no value", "nil", "boolean", "userdata", "number", "string",
|
2010-11-26 12:28:46 +00:00
|
|
|
"table", "function", "userdata", "thread", "proto", "cdata"
|
2009-12-08 18:46:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LJ_DATADEF const char *const lj_obj_itypename[] = { /* ORDER LJ_T */
|
|
|
|
"nil", "boolean", "boolean", "userdata", "string", "upval", "thread",
|
2010-11-26 12:28:46 +00:00
|
|
|
"proto", "function", "trace", "cdata", "table", "userdata", "number"
|
2009-12-08 18:46:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Compare two objects without calling metamethods. */
|
2013-05-12 22:34:15 +00:00
|
|
|
int LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2)
|
2009-12-08 18:46:35 +00:00
|
|
|
{
|
|
|
|
if (itype(o1) == itype(o2)) {
|
|
|
|
if (tvispri(o1))
|
|
|
|
return 1;
|
2010-04-20 23:45:58 +00:00
|
|
|
if (!tvisnum(o1))
|
|
|
|
return gcrefeq(o1->gcr, o2->gcr);
|
2011-02-16 23:44:14 +00:00
|
|
|
} else if (!tvisnumber(o1) || !tvisnumber(o2)) {
|
2009-12-08 18:46:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-16 23:44:14 +00:00
|
|
|
return numberVnum(o1) == numberVnum(o2);
|
2009-12-08 18:46:35 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 22:34:15 +00:00
|
|
|
/* Return pointer to object or its object data. */
|
2020-09-29 23:31:27 +00:00
|
|
|
const void * LJ_FASTCALL lj_obj_ptr(global_State *g, cTValue *o)
|
2013-05-12 22:34:15 +00:00
|
|
|
{
|
2020-09-29 23:31:27 +00:00
|
|
|
UNUSED(g);
|
2013-05-12 22:34:15 +00:00
|
|
|
if (tvisudata(o))
|
|
|
|
return uddata(udataV(o));
|
|
|
|
else if (tvislightud(o))
|
2020-09-29 23:31:27 +00:00
|
|
|
return lightudV(g, o);
|
2013-05-12 22:34:15 +00:00
|
|
|
else if (LJ_HASFFI && tviscdata(o))
|
|
|
|
return cdataptr(cdataV(o));
|
|
|
|
else if (tvisgcv(o))
|
|
|
|
return gcV(o);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|