lstate.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. ** $Id: lstate.h,v 1.16 1999/04/13 19:30:51 roberto Exp roberto $
  3. ** Global State
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lstate_h
  7. #define lstate_h
  8. #include <setjmp.h>
  9. #include "lobject.h"
  10. #include "lua.h"
  11. #include "luadebug.h"
  12. #define MAX_C_BLOCKS 10
  13. #define GARBAGE_BLOCK 150
  14. typedef int StkId; /* index to stack elements */
  15. /*
  16. ** "jmp_buf" may be an array, so it is better to make sure it has an
  17. ** address (and not that it *is* an address...)
  18. */
  19. struct lua_longjmp {
  20. jmp_buf b;
  21. };
  22. struct Stack {
  23. TObject *top;
  24. TObject *stack;
  25. TObject *last;
  26. };
  27. struct C_Lua_Stack {
  28. StkId base; /* when Lua calls C or C calls Lua, points to */
  29. /* the first slot after the last parameter. */
  30. StkId lua2C; /* points to first element of "array" lua2C */
  31. int num; /* size of "array" lua2C */
  32. };
  33. typedef struct stringtable {
  34. int size;
  35. int nuse; /* number of elements (including EMPTYs) */
  36. TaggedString **hash;
  37. } stringtable;
  38. enum Status {LOCK, HOLD, FREE, COLLECTED};
  39. struct ref {
  40. TObject o;
  41. enum Status status;
  42. };
  43. struct lua_State {
  44. /* thread-specific state */
  45. struct Stack stack; /* Lua stack */
  46. struct C_Lua_Stack Cstack; /* C2lua struct */
  47. struct lua_longjmp *errorJmp; /* current error recover point */
  48. char *Mbuffer; /* global buffer */
  49. int Mbuffbase; /* current first position of Mbuffer */
  50. int Mbuffsize; /* size of Mbuffer */
  51. int Mbuffnext; /* next position to fill in Mbuffer */
  52. struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
  53. int numCblocks; /* number of nested Cblocks */
  54. int debug;
  55. lua_CHFunction callhook;
  56. lua_LHFunction linehook;
  57. /* global state */
  58. GCnode rootproto; /* list of all prototypes */
  59. GCnode rootcl; /* list of all closures */
  60. GCnode roottable; /* list of all tables */
  61. GCnode rootglobal; /* list of strings with global values */
  62. stringtable *string_root; /* array of hash tables for strings and udata */
  63. struct IM *IMtable; /* table for tag methods */
  64. int last_tag; /* last used tag in IMtable */
  65. struct ref *refArray; /* locked objects */
  66. int refSize; /* size of refArray */
  67. unsigned long GCthreshold;
  68. unsigned long nblocks; /* number of 'blocks' currently allocated */
  69. };
  70. #define L lua_state
  71. #endif