lstate.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. ** $Id: lstate.h,v 1.54 2001/03/02 17:27:50 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. /*
  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. ls_nstr 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. void *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. Hash *type2tag; /* hash table from type names to tags */
  57. struct TM *TMtable; /* table for tag methods */
  58. int sizeTM; /* size of TMtable */
  59. int ntag; /* number of tags in TMtable */
  60. struct Ref *refArray; /* locked objects */
  61. int nref; /* first unused element in refArray */
  62. int sizeref; /* size of refArray */
  63. int refFree; /* list of free positions in refArray */
  64. lu_mem GCthreshold;
  65. lu_mem nblocks; /* number of `bytes' currently allocated */
  66. } global_State;
  67. /*
  68. ** `per thread' state
  69. */
  70. struct lua_State {
  71. LUA_USERSTATE
  72. StkId top; /* first free slot in the stack */
  73. CallInfo *ci; /* call info for current function */
  74. StkId stack_last; /* last free slot in the stack */
  75. Hash *gt; /* table for globals */
  76. global_State *G;
  77. StkId stack; /* stack base */
  78. int stacksize;
  79. lua_Hook callhook;
  80. lua_Hook linehook;
  81. int allowhooks;
  82. struct lua_longjmp *errorJmp; /* current error recover point */
  83. lua_State *next; /* circular double linked list of states */
  84. lua_State *previous;
  85. CallInfo basefunc;
  86. };
  87. #define G(L) (L->G)
  88. #endif