lstate.h 2.4 KB

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