lobject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. ** $Id: lobject.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
  3. ** Type definitions for Lua objects
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lobject_h
  7. #define lobject_h
  8. #include "lua.h"
  9. #include <limits.h>
  10. #ifndef real
  11. #define real float
  12. #endif
  13. #define Byte lua_Byte /* some systems have Byte as a predefined type */
  14. typedef unsigned char Byte; /* unsigned 8 bits */
  15. #define Word lua_Word /* some systems have Word as a predefined type */
  16. typedef unsigned short Word; /* unsigned 16 bits */
  17. #define MAX_WORD (USHRT_MAX-2) /* maximum value of a word (-2 for safety) */
  18. #define MAX_INT (INT_MAX-2) /* maximum value of a int (-2 for safety) */
  19. typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */
  20. /*
  21. ** Lua TYPES
  22. ** WARNING: if you change the order of this enumeration,
  23. ** grep "ORDER LUA_T"
  24. */
  25. typedef enum {
  26. LUA_T_NIL = -10,
  27. LUA_T_NUMBER = -9,
  28. LUA_T_STRING = -8,
  29. LUA_T_ARRAY = -7, /* array==table */
  30. LUA_T_PROTO = -6,
  31. LUA_T_FUNCTION = -5,
  32. LUA_T_CFUNCTION= -4,
  33. LUA_T_MARK = -3,
  34. LUA_T_CMARK = -2,
  35. LUA_T_LINE = -1,
  36. LUA_T_USERDATA = 0
  37. } lua_Type;
  38. #define NUM_TYPES 11
  39. typedef union {
  40. lua_CFunction f; /* LUA_T_CFUNCTION, LUA_T_CMARK */
  41. real n; /* LUA_T_NUMBER */
  42. struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */
  43. struct TProtoFunc *tf; /* LUA_T_PROTO */
  44. struct Closure *cl; /* LUA_T_FUNCTION, LUA_T_MARK */
  45. struct Hash *a; /* LUA_T_ARRAY */
  46. int i; /* LUA_T_LINE */
  47. } Value;
  48. typedef struct TObject {
  49. lua_Type ttype;
  50. Value value;
  51. } TObject;
  52. /*
  53. ** generic header for garbage collector lists
  54. */
  55. typedef struct GCnode {
  56. struct GCnode *next;
  57. int marked;
  58. } GCnode;
  59. /*
  60. ** String headers for string table
  61. */
  62. typedef struct TaggedString {
  63. GCnode head;
  64. int constindex; /* hint to reuse constants (= -1 if this is a userdata) */
  65. unsigned long hash;
  66. union {
  67. TObject globalval;
  68. struct {
  69. void *v; /* if this is a userdata, here is its value */
  70. int tag;
  71. } d;
  72. } u;
  73. char str[1]; /* \0 byte already reserved */
  74. } TaggedString;
  75. /*
  76. ** Function Prototypes
  77. */
  78. typedef struct TProtoFunc {
  79. GCnode head;
  80. Byte *code; /* ends with opcode ENDCODE */
  81. int lineDefined;
  82. TaggedString *fileName;
  83. struct TObject *consts;
  84. int nconsts;
  85. struct LocVar *locvars; /* ends with line = -1 */
  86. int nupvalues;
  87. } TProtoFunc;
  88. typedef struct LocVar {
  89. TaggedString *varname; /* NULL signals end of scope */
  90. int line;
  91. } LocVar;
  92. /* Macros to access structure members */
  93. #define ttype(o) ((o)->ttype)
  94. #define nvalue(o) ((o)->value.n)
  95. #define svalue(o) ((o)->value.ts->str)
  96. #define tsvalue(o) ((o)->value.ts)
  97. #define clvalue(o) ((o)->value.cl)
  98. #define avalue(o) ((o)->value.a)
  99. #define fvalue(o) ((o)->value.f)
  100. #define tfvalue(o) ((o)->value.tf)
  101. /*
  102. ** Closures
  103. */
  104. typedef struct Closure {
  105. GCnode head;
  106. TObject consts[1]; /* at least one for prototype */
  107. } Closure;
  108. typedef struct node {
  109. TObject ref;
  110. TObject val;
  111. } Node;
  112. typedef struct Hash {
  113. GCnode head;
  114. Node *node;
  115. int nhash;
  116. int nuse;
  117. int htag;
  118. } Hash;
  119. extern long luaO_nentities;
  120. extern char *luaO_typenames[];
  121. int luaO_equalObj (TObject *t1, TObject *t2);
  122. int luaO_redimension (int oldsize);
  123. int luaO_findstring (char *name, char *list[]);
  124. void luaO_insertlist (GCnode *root, GCnode *node);
  125. #endif