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

lobject.h

Go to the documentation of this file.
00001 /*
00002 ** Type definitions for Lua objects
00003 ** See Copyright Notice in lua.h
00004 */
00005 
00006 #ifndef GRIM_LOBJECT_H
00007 #define GRIM_LOBJECT_H
00008 
00009 #include "engines/grim/lua/lua.h"
00010 
00011 namespace Grim {
00012 
00013 #ifdef LUA_DEBUG
00014 #include "engines/grim/lua/lauxlib.h"
00015 #define LUA_INTERNALERROR(s)    luaL_verror("INTERNAL ERROR - %s [%s:%d]", (s), __FILE__, __LINE__)
00016 #define LUA_ASSERT(c, s)            { if (!(c)) LUA_INTERNALERROR(s); }
00017 #else
00018 #define LUA_INTERNALERROR(s)    // empty
00019 #define LUA_ASSERT(c, s)            // empty
00020 #endif
00021 
00022 #define MAX_INT         (2147483647 - 2)  // maximum value of an int (-2 for safety)
00023 #define MAX_WORD        (65534U)
00024 
00025 /*
00026 ** Lua TYPES
00027 ** WARNING: if you change the order of this enumeration,
00028 ** grep "ORDER LUA_T"
00029 */
00030 typedef enum {
00031     LUA_T_USERDATA =  0,  // tag default for userdata
00032     LUA_T_NUMBER   = -1,  // fixed tag for numbers
00033     LUA_T_STRING   = -2,  // fixed tag for strings
00034     LUA_T_ARRAY    = -3,  // tag default for tables (or arrays)
00035     LUA_T_PROTO    = -4,  // fixed tag for functions
00036     LUA_T_CPROTO   = -5,  // fixed tag for Cfunctions
00037     LUA_T_TASK     = -6,  // task tag
00038     LUA_T_NIL      = -7,  // last "pre-defined" tag
00039     LUA_T_CLOSURE  = -8,
00040     LUA_T_CLMARK   = -9,  // mark for closures
00041     LUA_T_PMARK    = -10, // mark for Lua prototypes
00042     LUA_T_CMARK    = -11, // mark for C prototypes
00043     LUA_T_LINE     = -12
00044 } lua_Type;
00045 
00046 #define NUM_TYPES 12
00047 #define NUM_TAGS  8
00048 
00049 typedef struct UserData {
00050     int32 id;
00051     int32 tag;
00052 } UserData;
00053 
00054 typedef union {
00055     lua_CFunction f;  // LUA_T_CPROTO, LUA_T_CMARK
00056     float n;  // LUA_T_NUMBER
00057     struct TaggedString *ts;  // LUA_T_STRING
00058     struct TProtoFunc *tf;  // LUA_T_PROTO, LUA_T_PMARK
00059     struct Closure *cl;  // LUA_T_CLOSURE, LUA_T_CLMARK
00060     struct Hash *a;  // LUA_T_ARRAY
00061     int32 i;  // LUA_T_LINE
00062     struct UserData ud;  // LUA_T_USERDATA
00063 } Value;
00064 
00065 typedef struct TObject {
00066     lua_Type ttype;
00067     Value value;
00068 } TObject;
00069 
00070 /*
00071 ** generic header for garbage collector lists
00072 */
00073 typedef struct GCnode {
00074     struct GCnode *next;
00075     int32 marked;
00076 } GCnode;
00077 
00078 /*
00079 ** String headers for string table
00080 */
00081 
00082 typedef struct TaggedString {
00083     GCnode head;
00084     int32 constindex;  // hint to reuse constants (= -1 if this is a userdata)
00085     uint32 hash;
00086     TObject globalval;
00087     char str[1];   // \0 byte already reserved
00088 } TaggedString;
00089 
00090 /*
00091 ** Function Prototypes
00092 */
00093 typedef struct TProtoFunc {
00094     GCnode head;
00095     struct TObject *consts;
00096     int32 nconsts;
00097     byte *code;  // ends with opcode ENDCODE
00098     int32 lineDefined;
00099     TaggedString  *fileName;
00100     struct LocVar *locvars;  // ends with line = -1
00101 } TProtoFunc;
00102 
00103 typedef struct LocVar {
00104     TaggedString *varname;           // NULL signals end of scope
00105     int32 line;
00106 } LocVar;
00107 
00108 // Macros to access structure members
00109 #define ttype(o)        ((o)->ttype)
00110 #define nvalue(o)       ((o)->value.n)
00111 #define svalue(o)       ((o)->value.ts->str)
00112 #define tsvalue(o)      ((o)->value.ts)
00113 #define clvalue(o)      ((o)->value.cl)
00114 #define avalue(o)       ((o)->value.a)
00115 #define fvalue(o)       ((o)->value.f)
00116 #define tfvalue(o)      ((o)->value.tf)
00117 #define protovalue(o)   ((o)->value.cl->consts)
00118 
00119 
00120 /*
00121 ** Closures
00122 */
00123 typedef struct Closure {
00124     GCnode head;
00125     int32 nelems;  // not included the first one (always the prototype)
00126     TObject consts[1];  // at least one for prototype
00127 } Closure;
00128 
00129 typedef struct Node {
00130     TObject ref;
00131     TObject val;
00132 } Node;
00133 
00134 typedef struct Hash {
00135     GCnode head;
00136     Node *node;
00137     int32 nhash;
00138     int32 nuse;
00139     int32 htag;
00140 } Hash;
00141 
00142 extern const char *luaO_typenames[];
00143 extern TObject luaO_nilobject;
00144 
00145 int32 luaO_equalObj(TObject *t1, TObject *t2);
00146 int32 luaO_redimension(int32 oldsize);
00147 int luaO_findstring(const char *name, const char *list[]);
00148 void luaO_insertlist(GCnode *root, GCnode *node);
00149 
00150 #define luaO_memup(d, s, n)     memmove(d, s, n)
00151 #define luaO_memdown(d, s, n)   memmove(d, s, n)
00152 
00153 } // end of namespace Grim
00154 
00155 #endif


Generated on Sat Nov 16 2019 05:00:39 for ResidualVM by doxygen 1.7.1
curved edge   curved edge