ScummVM API documentation
lobject.h
1 /*
2 ** Type definitions for Lua objects
3 ** See Copyright Notice in lua.h
4 */
5 
6 #ifndef GRIM_LOBJECT_H
7 #define GRIM_LOBJECT_H
8 
9 #include "engines/grim/lua/lua.h"
10 
11 namespace Grim {
12 
13 #ifdef LUA_DEBUG
14 #include "engines/grim/lua/lauxlib.h"
15 #define LUA_INTERNALERROR(s) luaL_verror("INTERNAL ERROR - %s [%s:%d]", (s), __FILE__, __LINE__)
16 #define LUA_ASSERT(c, s) { if (!(c)) LUA_INTERNALERROR(s); }
17 #else
18 #define LUA_INTERNALERROR(s) // empty
19 #define LUA_ASSERT(c, s) // empty
20 #endif
21 
22 #define MAX_INT (2147483647 - 2) // maximum value of an int (-2 for safety)
23 #define MAX_WORD (65534U)
24 
25 /*
26 ** Lua TYPES
27 ** WARNING: if you change the order of this enumeration,
28 ** grep "ORDER LUA_T"
29 */
30 typedef enum {
31  LUA_T_USERDATA = 0, // tag default for userdata
32  LUA_T_NUMBER = -1, // fixed tag for numbers
33  LUA_T_STRING = -2, // fixed tag for strings
34  LUA_T_ARRAY = -3, // tag default for tables (or arrays)
35  LUA_T_PROTO = -4, // fixed tag for functions
36  LUA_T_CPROTO = -5, // fixed tag for Cfunctions
37  LUA_T_TASK = -6, // task tag
38  LUA_T_NIL = -7, // last "pre-defined" tag
39  LUA_T_CLOSURE = -8,
40  LUA_T_CLMARK = -9, // mark for closures
41  LUA_T_PMARK = -10, // mark for Lua prototypes
42  LUA_T_CMARK = -11, // mark for C prototypes
43  LUA_T_LINE = -12
44 } lua_Type;
45 
46 #define NUM_TYPES 12
47 #define NUM_TAGS 8
48 
49 typedef struct UserData {
50  int32 id;
51  int32 tag;
52 } UserData;
53 
54 typedef union {
55  lua_CFunction f; // LUA_T_CPROTO, LUA_T_CMARK
56  float n; // LUA_T_NUMBER
57  struct TaggedString *ts; // LUA_T_STRING
58  struct TProtoFunc *tf; // LUA_T_PROTO, LUA_T_PMARK
59  struct Closure *cl; // LUA_T_CLOSURE, LUA_T_CLMARK
60  struct Hash *a; // LUA_T_ARRAY
61  int32 i; // LUA_T_LINE
62  struct UserData ud; // LUA_T_USERDATA
63 } Value;
64 
65 typedef struct TObject {
66  lua_Type ttype;
67  Value value;
68 } TObject;
69 
70 /*
71 ** generic header for garbage collector lists
72 */
73 typedef struct GCnode {
74  struct GCnode *next;
75  int32 marked;
76 } GCnode;
77 
78 /*
79 ** String headers for string table
80 */
81 
82 typedef struct TaggedString {
83  GCnode head;
84  int32 constindex; // hint to reuse constants (= -1 if this is a userdata)
85  uint32 hash;
86  TObject globalval;
87  char str[1]; // \0 byte already reserved
88 } TaggedString;
89 
90 /*
91 ** Function Prototypes
92 */
93 typedef struct TProtoFunc {
94  GCnode head;
95  struct TObject *consts;
96  int32 nconsts;
97  byte *code; // ends with opcode ENDCODE
98  int32 lineDefined;
99  TaggedString *fileName;
100  struct LocVar *locvars; // ends with line = -1
101 } TProtoFunc;
102 
103 typedef struct LocVar {
104  TaggedString *varname; // NULL signals end of scope
105  int32 line;
106 } LocVar;
107 
108 // Macros to access structure members
109 #define ttype(o) ((o)->ttype)
110 #define nvalue(o) ((o)->value.n)
111 #define svalue(o) ((o)->value.ts->str)
112 #define tsvalue(o) ((o)->value.ts)
113 #define clvalue(o) ((o)->value.cl)
114 #define avalue(o) ((o)->value.a)
115 #define fvalue(o) ((o)->value.f)
116 #define tfvalue(o) ((o)->value.tf)
117 #define protovalue(o) ((o)->value.cl->consts)
118 
119 /*
120 ** Closures
121 */
122 typedef struct Closure {
123  GCnode head;
124  int32 nelems; // not included the first one (always the prototype)
125  TObject consts[1]; // at least one for prototype
126 } Closure;
127 
128 typedef struct Node {
129  TObject ref;
130  TObject val;
131 } Node;
132 
133 typedef struct Hash {
134  GCnode head;
135  Node *node;
136  int32 nhash;
137  int32 nuse;
138  int32 htag;
139 } Hash;
140 
141 extern const char *luaO_typenames[];
142 extern TObject luaO_nilobject;
143 
144 int32 luaO_equalObj(TObject *t1, TObject *t2);
145 int32 luaO_redimension(int32 oldsize);
146 int luaO_findstring(const char *name, const char *list[]);
147 void luaO_insertlist(GCnode *root, GCnode *node);
148 
149 #define luaO_memup(d, s, n) memmove(d, s, n)
150 #define luaO_memdown(d, s, n) memmove(d, s, n)
151 
152 } // end of namespace Grim
153 
154 #endif
Definition: lobject.h:65
Definition: lobject.h:93
Definition: lstate.h:56
Definition: lobject.h:82
Definition: actor.h:33
Definition: lobject.h:54
Definition: lobject.h:49
Definition: lobject.h:122
Definition: lobject.h:103
Definition: lobject.h:73
Definition: lobject.h:133
Definition: lobject.h:128