lstate.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. ** $Id: lstate.h,v 1.49 2001/02/01 17:40:48 roberto Exp roberto $
  3. ** Global State
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lstate_h
  7. #define lstate_h
  8. #include "lobject.h"
  9. #include "lua.h"
  10. #include "luadebug.h"
  11. /*
  12. ** macros that control all entries and exits from Lua core machine
  13. ** (mainly for thread syncronization)
  14. */
  15. #ifndef LUA_LOCK
  16. #define LUA_LOCK(L) ((void) 0)
  17. #endif
  18. #ifndef LUA_UNLOCK
  19. #define LUA_UNLOCK(L) ((void) 0)
  20. #endif
  21. /*
  22. ** macro to allow the inclusion of user information in Lua state
  23. */
  24. #ifndef LUA_USERSTATE
  25. #define LUA_USERSTATE
  26. #endif
  27. typedef TObject *StkId; /* index to stack elements */
  28. /*
  29. ** marks for Reference array
  30. */
  31. #define NONEXT -1 /* to end the free list */
  32. #define HOLD -2
  33. #define COLLECTED -3
  34. #define LOCK -4
  35. struct Ref {
  36. TObject o;
  37. int st; /* can be LOCK, HOLD, COLLECTED, or next (for free list) */
  38. };
  39. struct lua_longjmp; /* defined in ldo.c */
  40. struct TM; /* defined in ltm.h */
  41. typedef struct stringtable {
  42. int size;
  43. luint32 nuse; /* number of elements */
  44. TString **hash;
  45. } stringtable;
  46. /*
  47. ** "global state", shared by all threads of this state
  48. */
  49. typedef struct global_State {
  50. char *Mbuffer; /* global buffer */
  51. size_t Mbuffsize; /* size of Mbuffer */
  52. Proto *rootproto; /* list of all prototypes */
  53. Closure *rootcl; /* list of all closures */
  54. Hash *roottable; /* list of all tables */
  55. stringtable strt; /* hash table for strings */
  56. stringtable udt; /* hash table for udata */
  57. Hash *type2tag; /* hash table from type names to tags */
  58. struct TM *TMtable; /* table for tag methods */
  59. int sizeTM; /* size of TMtable */
  60. int ntag; /* number of tags in TMtable */
  61. struct Ref *refArray; /* locked objects */
  62. int nref; /* first unused element in refArray */
  63. int sizeref; /* size of refArray */
  64. int refFree; /* list of free positions in refArray */
  65. mem_int GCthreshold;
  66. mem_int nblocks; /* number of `bytes' currently allocated */
  67. } global_State;
  68. /*
  69. ** "per thread" state
  70. */
  71. struct lua_State {
  72. LUA_USERSTATE
  73. StkId top; /* first free slot in the stack */
  74. StkId stack; /* stack base */
  75. StkId stack_last; /* last free slot in the stack */
  76. int stacksize;
  77. StkId Cbase; /* base for current C function */
  78. Hash *gt; /* table for globals */
  79. global_State *G;
  80. lua_Hook callhook;
  81. lua_Hook linehook;
  82. int allowhooks;
  83. struct lua_longjmp *errorJmp; /* current error recover point */
  84. lua_State *next; /* circular double linked list of states */
  85. lua_State *previous;
  86. };
  87. #define G(L) (L->G)
  88. #endif