ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

lobject.cpp

Go to the documentation of this file.
00001 /*
00002 ** Some generic functions over Lua objects
00003 ** See Copyright Notice in lua.h
00004 */
00005 
00006 #define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
00007 #define FORBIDDEN_SYMBOL_EXCEPTION_longjmp
00008 
00009 #include "engines/grim/lua/lobject.h"
00010 #include "engines/grim/lua/lua.h"
00011 #include "engines/grim/lua/lstring.h"
00012 #include "engines/grim/lua/lstate.h"
00013 
00014 namespace Grim {
00015 
00016 const char *luaO_typenames[] = { // ORDER LUA_T
00017     "userdata", "number", "string", "table", "function", "function", "task",
00018     "nil", "function", "mark", "mark", "mark", "line", nullptr
00019 };
00020 
00021 TObject luaO_nilobject = { LUA_T_NIL, { nullptr } };
00022 
00023 
00024 // hash dimensions values
00025 static int32 dimensions[] = {
00026     5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421,
00027     12853, 25717, 51437, 102811, 205619, 411233, 822433,
00028     1644817, 3289613, 6579211, 13158023, MAX_INT
00029 };
00030 
00031 int32 luaO_redimension(int32 oldsize) {
00032     int32 i;
00033     for (i = 0; dimensions[i] < MAX_INT; i++) {
00034         if (dimensions[i] > oldsize)
00035             return dimensions[i];
00036     }
00037     lua_error("table overflow");
00038     return 0;  // to avoid warnings
00039 }
00040 
00041 int32 luaO_equalObj(TObject *t1, TObject *t2) {
00042     if (ttype(t1) != ttype(t2))
00043         return 0;
00044     switch (ttype(t1)) {
00045     case LUA_T_NIL:
00046         return 1;
00047     case LUA_T_NUMBER:
00048         return nvalue(t1) == nvalue(t2);
00049     case LUA_T_USERDATA:
00050         return (t1->value.ud.id == t2->value.ud.id && t1->value.ud.tag == t2->value.ud.tag);
00051     case LUA_T_STRING:
00052         return svalue(t1) == svalue(t2);
00053     case LUA_T_ARRAY:
00054         return avalue(t1) == avalue(t2);
00055     case LUA_T_PROTO:
00056         return tfvalue(t1) == tfvalue(t2);
00057     case LUA_T_CPROTO:
00058         return fvalue(t1) == fvalue(t2);
00059     case LUA_T_CLOSURE:
00060         return t1->value.cl == t2->value.cl;
00061     case LUA_T_TASK:
00062         return nvalue(t1) == nvalue(t2);
00063     default:
00064 #ifdef LUA_DEBUG
00065         LUA_INTERNALERROR("internal error in `lua_equalObj'");
00066 #endif
00067         return 0; // UNREACHABLE
00068     }
00069 }
00070 
00071 int luaO_findstring(const char *name, const char *list[]) {
00072     int i;
00073 
00074     for (i = 0; list[i]; i++)
00075         if (strcmp(list[i], name) == 0)
00076             return i;
00077     return -1;  // name not found
00078 }
00079 
00080 void luaO_insertlist(GCnode *root, GCnode *node) {
00081     node->next = root->next;
00082     root->next = node;
00083     node->marked = 0;
00084 }
00085 
00086 } // end of namespace Grim
00087 


Generated on Sat Apr 20 2019 05:03:05 for ResidualVM by doxygen 1.7.1
curved edge   curved edge