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

lstate.h

Go to the documentation of this file.
00001 /*
00002 ** Global State
00003 ** See Copyright Notice in lua.h
00004 */
00005 
00006 #ifndef GRIM_LSTATE_H
00007 #define GRIM_LSTATE_H
00008 
00009 #include "engines/grim/lua/lobject.h"
00010 
00011 #include <setjmp.h>
00012 
00013 namespace Grim {
00014 
00015 #define MAX_C_BLOCKS 10
00016 #define GARBAGE_BLOCK 150
00017 
00018 /* The pause status for the scripts is stored in one byte in the savegame.
00019  *
00020  * The "single script pause" status will be stored in the highest significant bit.
00021  * For GRIM that flag is never set because GRIM does not pause single scripts.
00022  *
00023  * The "all scripts pause" status is a number which counts, how often
00024  * pause_scripts(TRUE) was called without a corresponding unpause_scripts() call.
00025  * The value is stored in the lower 7 bit of the pause status byte.
00026  * For GRIM, since the (un)pause_scripts() are called symmetrically, only
00027  * the lowest bit will be used.
00028  */
00029 #define LUA_SG_ALL_PAUSED 0x7f
00030 #define LUA_SG_PAUSED     0x80
00031 
00032 typedef int32 StkId;  /* index to stack elements */
00033 
00034 struct Stack {
00035     TObject *top;
00036     TObject *stack;
00037     TObject *last;
00038 };
00039 
00040 struct C_Lua_Stack {
00041     StkId base;  // when Lua calls C or C calls Lua, points to
00042     // the first slot after the last parameter.
00043     StkId lua2C; // points to first element of "array" lua2C
00044     int32 num;     // size of "array" lua2C
00045 };
00046 
00047 
00048 typedef struct {
00049     int32 size;
00050     int32 nuse;  // number of elements (including EMPTYs)
00051     TaggedString **hash;
00052 } stringtable;
00053 
00054 enum Status { LOCK, HOLD, FREE, COLLECTED };
00055 
00056 struct ref {
00057     TObject o;
00058     enum Status status;
00059 };
00060 
00061 struct CallInfo {
00062     Closure *c;
00063     TProtoFunc *tf;  // Set to NULL for C function
00064     StkId base;
00065     byte *pc;
00066     int32 nResults;
00067 };
00068 
00069 struct lua_Task;
00070 
00071 extern GCnode rootproto;
00072 extern GCnode rootcl;
00073 extern GCnode rootglobal;
00074 extern GCnode roottable;
00075 extern struct ref *refArray;
00076 extern int32 refSize;
00077 extern int32 GCthreshold;
00078 extern int32 nblocks;
00079 extern int32 Mbuffsize;
00080 extern int32 Mbuffnext;
00081 extern char *Mbuffbase;
00082 extern char *Mbuffer;
00083 extern TObject errorim;
00084 extern stringtable *string_root;
00085 extern int32 last_tag;
00086 extern struct IM *IMtable;
00087 extern int32 IMtable_size;
00088 
00089 struct LState {
00090     LState *prev; // handle to previous state in list
00091     LState *next; // handle to next state in list
00092     int all_paused; // counter of often pause_scripts(TRUE) was called
00093     bool paused;    // true if this particular script has been paused
00094     int32 state_counter1;
00095     int32 state_counter2;
00096     bool updated;
00097     Stack stack;  // Lua stack
00098     C_Lua_Stack Cstack;  // C2lua struct
00099     struct FuncState *mainState, *currState;  // point to local structs in yacc
00100     struct LexState *lexstate;  // point to local struct in yacc
00101     jmp_buf *errorJmp;  // current error recover point
00102     lua_Task *task; // handle to task
00103     lua_Task *some_task;
00104     uint32 id; // current id of task
00105     TObject taskFunc;
00106     struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
00107     int numCblocks; // number of nested Cblocks
00108     int sleepFor;
00109 };
00110 
00111 extern LState *lua_state, *lua_rootState;
00112 
00113 extern int globalTaskSerialId;
00114 
00115 void lua_stateinit(LState *state);
00116 void lua_statedeinit(LState *state);
00117 void lua_resetglobals();
00118 
00119 } // end of namespace Grim
00120 
00121 #endif


Generated on Sat May 25 2019 05:00:48 for ResidualVM by doxygen 1.7.1
curved edge   curved edge