lstate.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. ** $Id: lstate.h,v 1.68 2001/12/18 20:52:30 roberto Exp $
  3. ** Global State
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lstate_h
  7. #define lstate_h
  8. #include "lua.h"
  9. #include "lobject.h"
  10. #include "ltm.h"
  11. #include "luadebug.h"
  12. /*
  13. ** macros for thread syncronization inside Lua core machine:
  14. ** all accesses to the global state and to global objects are syncronized.
  15. ** Because threads can read the stack of other threads
  16. ** (when running garbage collection),
  17. ** a thread must also syncronize any write-access to its own stack.
  18. ** Unsyncronized accesses are allowed only when reading its own stack,
  19. ** or when reading immutable fields from global objects
  20. ** (such as string values and udata values).
  21. */
  22. #ifndef lua_lock
  23. #define lua_lock(L) ((void) 0)
  24. #endif
  25. #ifndef lua_unlock
  26. #define lua_unlock(L) ((void) 0)
  27. #endif
  28. /*
  29. ** macro to allow the inclusion of user information in Lua state
  30. */
  31. #ifndef LUA_USERSTATE
  32. #define LUA_USERSTATE
  33. #endif
  34. struct lua_longjmp; /* defined in ldo.c */
  35. /*
  36. ** reserve init of stack to store some global values
  37. */
  38. /* default event table (both for tables and udata) */
  39. #define defaultet(L) (L->stack)
  40. /* table of globals */
  41. #define gt(L) (L->stack + 1)
  42. /* registry */
  43. #define registry(L) (L->stack + 2)
  44. #define RESERVED_STACK_PREFIX 3
  45. typedef struct stringtable {
  46. int size;
  47. ls_nstr nuse; /* number of elements */
  48. TString **hash;
  49. } stringtable;
  50. /*
  51. ** informations about a call
  52. */
  53. typedef struct CallInfo {
  54. StkId base; /* base for called function */
  55. const Instruction *savedpc;
  56. lua_Hook linehook;
  57. StkId top; /* top for this function (when it's a Lua function) */
  58. /* extra information for debugging */
  59. const Instruction **pc;
  60. int lastpc; /* last pc traced */
  61. int line; /* current line */
  62. int refi; /* current index in `lineinfo' */
  63. } CallInfo;
  64. #define ci_func(ci) (clvalue((ci)->base - 1))
  65. /*
  66. ** `global state', shared by all threads of this state
  67. */
  68. typedef struct global_State {
  69. void *Mbuffer; /* global buffer */
  70. size_t Mbuffsize; /* size of Mbuffer */
  71. stringtable strt; /* hash table for strings */
  72. lu_mem GCthreshold;
  73. lu_mem nblocks; /* number of `bytes' currently allocated */
  74. Proto *rootproto; /* list of all prototypes */
  75. Closure *rootcl; /* list of all closures */
  76. Table *roottable; /* list of all tables */
  77. UpVal *rootupval; /* list of closed up values */
  78. Udata *rootudata; /* list of all userdata */
  79. Udata *tmudata; /* list of userdata to be GC */
  80. TString *tmname[TM_N]; /* array with tag-method names */
  81. } global_State;
  82. /*
  83. ** `per thread' state
  84. */
  85. struct lua_State {
  86. LUA_USERSTATE
  87. StkId top; /* first free slot in the stack */
  88. CallInfo *ci; /* call info for current function */
  89. StkId stack_last; /* last free slot in the stack */
  90. StkId stack; /* stack base */
  91. int stacksize;
  92. CallInfo *end_ci; /* points after end of ci array*/
  93. CallInfo *base_ci; /* array of CallInfo's */
  94. int size_ci; /* size of array `base_ci' */
  95. global_State *_G;
  96. lua_Hook callhook;
  97. lua_Hook linehook;
  98. int allowhooks;
  99. struct lua_longjmp *errorJmp; /* current error recover point */
  100. UpVal *openupval; /* list of open upvalues in this stack */
  101. lua_State *next; /* circular double linked list of states */
  102. lua_State *previous;
  103. };
  104. #define G(L) (L->_G)
  105. #endif