lstate.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ** $Id: lstate.h,v 1.57 2001/06/06 18:00:19 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 for thread syncronization inside Lua core machine:
  13. ** all accesses to the global state and to global objects are syncronized.
  14. ** Because threads can read the stack of other threads
  15. ** (when running garbage collection),
  16. ** a thread must also syncronize any write-access to its own stack.
  17. ** Unsyncronized accesses are allowed only when reading its own stack,
  18. ** or when reading immutable fields from global objects
  19. ** (such as string values and udata values).
  20. */
  21. #ifndef lua_lock
  22. #define lua_lock(L) ((void) 0)
  23. #endif
  24. #ifndef lua_unlock
  25. #define lua_unlock(L) ((void) 0)
  26. #endif
  27. /*
  28. ** macro to allow the inclusion of user information in Lua state
  29. */
  30. #ifndef LUA_USERSTATE
  31. #define LUA_USERSTATE
  32. #endif
  33. struct lua_longjmp; /* defined in ldo.c */
  34. struct TM; /* defined in ltm.h */
  35. typedef struct stringtable {
  36. int size;
  37. ls_nstr nuse; /* number of elements */
  38. TString **hash;
  39. } stringtable;
  40. /*
  41. ** `global state', shared by all threads of this state
  42. */
  43. typedef struct global_State {
  44. void *Mbuffer; /* global buffer */
  45. size_t Mbuffsize; /* size of Mbuffer */
  46. Proto *rootproto; /* list of all prototypes */
  47. Closure *rootcl; /* list of all closures */
  48. Hash *roottable; /* list of all tables */
  49. Udata *rootudata; /* list of all userdata */
  50. stringtable strt; /* hash table for strings */
  51. Hash *type2tag; /* hash table from type names to tags */
  52. Hash *registry; /* (strong) registry table */
  53. Hash *weakregistry; /* weakregistry table */
  54. struct TM *TMtable; /* table for tag methods */
  55. int sizeTM; /* size of TMtable */
  56. int ntag; /* number of tags in TMtable */
  57. lu_mem GCthreshold;
  58. lu_mem nblocks; /* number of `bytes' currently allocated */
  59. } global_State;
  60. /*
  61. ** `per thread' state
  62. */
  63. struct lua_State {
  64. LUA_USERSTATE
  65. StkId top; /* first free slot in the stack */
  66. CallInfo *ci; /* call info for current function */
  67. StkId stack_last; /* last free slot in the stack */
  68. Hash *gt; /* table for globals */
  69. global_State *G;
  70. StkId stack; /* stack base */
  71. int stacksize;
  72. lua_Hook callhook;
  73. lua_Hook linehook;
  74. int allowhooks;
  75. struct lua_longjmp *errorJmp; /* current error recover point */
  76. lua_State *next; /* circular double linked list of states */
  77. lua_State *previous;
  78. CallInfo basefunc;
  79. };
  80. #define G(L) (L->G)
  81. #endif