lstate.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. ** $Id: lstate.h,v 1.84 2002/04/23 15:04:39 roberto Exp roberto $
  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. #ifndef lua_userstateopen
  35. #define lua_userstateopen(l)
  36. #endif
  37. struct lua_longjmp; /* defined in ldo.c */
  38. /*
  39. ** array of `global' objects
  40. */
  41. #define NUMGLOBS 3
  42. /* default meta table (both for tables and udata) */
  43. #define defaultmeta(L) (L->globs)
  44. /* table of globals */
  45. #define gt(L) (L->globs + 1)
  46. /* registry */
  47. #define registry(L) (L->globs + 2)
  48. /* space to handle TM calls and other temporary overflows */
  49. #define EXTRA_STACK 5
  50. #define BASIC_CI_SIZE 8
  51. #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
  52. typedef struct stringtable {
  53. TString **hash;
  54. ls_nstr nuse; /* number of elements */
  55. int size;
  56. } stringtable;
  57. /*
  58. ** informations about a call
  59. */
  60. typedef struct CallInfo {
  61. StkId base; /* base for called function */
  62. const Instruction *savedpc;
  63. StkId top; /* top for this function (when it's a Lua function) */
  64. const Instruction **pc; /* points to `pc' variable in `luaV_execute' */
  65. StkId *pb; /* points to `base' variable in `luaV_execute' */
  66. int yield_results;
  67. } CallInfo;
  68. #define ci_func(ci) (clvalue((ci)->base - 1))
  69. /*
  70. ** `global state', shared by all threads of this state
  71. */
  72. typedef struct global_State {
  73. stringtable strt; /* hash table for strings */
  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. void *Mbuffer; /* global buffer */
  81. size_t Mbuffsize; /* size of Mbuffer */
  82. lu_mem GCthreshold;
  83. lu_mem nblocks; /* number of `bytes' currently allocated */
  84. lua_CFunction panic; /* to be called in unprotected errors */
  85. Node dummynode[1]; /* common node array for all empty tables */
  86. TString *tmname[TM_N]; /* array with tag-method names */
  87. } global_State;
  88. /*
  89. ** `per thread' state
  90. */
  91. struct lua_State {
  92. LUA_USERSTATE
  93. StkId top; /* first free slot in the stack */
  94. CallInfo *ci; /* call info for current function */
  95. StkId stack_last; /* last free slot in the stack */
  96. StkId stack; /* stack base */
  97. CallInfo *end_ci; /* points after end of ci array*/
  98. CallInfo *base_ci; /* array of CallInfo's */
  99. global_State *l_G;
  100. TObject globs[NUMGLOBS]; /* registry, table of globals, etc. */
  101. struct lua_longjmp *errorJmp; /* current error recover point */
  102. UpVal *openupval; /* list of open upvalues in this stack */
  103. lua_State *next; /* circular double linked list of states */
  104. lua_State *previous;
  105. int stacksize;
  106. int size_ci; /* size of array `base_ci' */
  107. int allowhooks;
  108. lua_Hook callhook;
  109. lua_Hook linehook;
  110. };
  111. #define G(L) (L->l_G)
  112. void luaE_closethread (lua_State *OL, lua_State *L);
  113. #endif