lobject.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. ** $Id: lobject.h,v 2.138 2018/02/25 12:48:16 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 <stdarg.h>
  9. #include "llimits.h"
  10. #include "lua.h"
  11. /*
  12. ** Extra tags for non-values
  13. */
  14. #define LUA_TUPVAL LUA_NUMTAGS /* upvalues */
  15. #define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */
  16. /*
  17. ** number of all possible tags (including LUA_TNONE)
  18. */
  19. #define LUA_TOTALTAGS (LUA_TPROTO + 2)
  20. /*
  21. ** tags for Tagged Values have the following use of bits:
  22. ** bits 0-3: actual tag (a LUA_T* value)
  23. ** bits 4-5: variant bits
  24. ** bit 6: whether value is collectable
  25. */
  26. /*
  27. ** Union of all Lua values
  28. */
  29. typedef union Value {
  30. struct GCObject *gc; /* collectable objects */
  31. void *p; /* light userdata */
  32. int b; /* booleans */
  33. lua_CFunction f; /* light C functions */
  34. lua_Integer i; /* integer numbers */
  35. lua_Number n; /* float numbers */
  36. } Value;
  37. /*
  38. ** Tagged Values. This is the basic representation of values in Lua:
  39. ** an actual value plus a tag with its type.
  40. */
  41. #define TValuefields Value value_; lu_byte tt_
  42. typedef struct TValue {
  43. TValuefields;
  44. } TValue;
  45. #define val_(o) ((o)->value_)
  46. #define valraw(o) (&val_(o))
  47. /* raw type tag of a TValue */
  48. #define rttype(o) ((o)->tt_)
  49. /* tag with no variants (bits 0-3) */
  50. #define novariant(x) ((x) & 0x0F)
  51. /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
  52. #define ttyperaw(t) ((t) & 0x3F)
  53. #define ttype(o) ttyperaw(rttype(o))
  54. /* type tag of a TValue with no variants (bits 0-3) */
  55. #define ttnov(o) (novariant(rttype(o)))
  56. /* Macros to test type */
  57. #define checktag(o,t) (rttype(o) == (t))
  58. #define checktype(o,t) (ttnov(o) == (t))
  59. /* Macros for internal tests */
  60. #define righttt(obj) (ttype(obj) == gcvalue(obj)->tt)
  61. #define checkliveness(L,obj) \
  62. lua_longassert(!iscollectable(obj) || \
  63. (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))
  64. /* Macros to set values */
  65. #define settt_(o,t) ((o)->tt_=(t))
  66. #define setobj(L,obj1,obj2) \
  67. { TValue *io1=(obj1); const TValue *io2=(obj2); \
  68. io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
  69. (void)L; checkliveness(L,io1); lua_assert(!isreallyempty(io1)); }
  70. /*
  71. ** different types of assignments, according to destination
  72. */
  73. /* from stack to stack */
  74. #define setobjs2s(L,o1,o2) setobj(L,s2v(o1),s2v(o2))
  75. /* to stack (not from same stack) */
  76. #define setobj2s(L,o1,o2) setobj(L,s2v(o1),o2)
  77. /* from table to same table */
  78. #define setobjt2t setobj
  79. /* to new object */
  80. #define setobj2n setobj
  81. /* to table */
  82. #define setobj2t setobj
  83. typedef union StackValue {
  84. TValue val;
  85. } StackValue;
  86. typedef StackValue *StkId; /* index to stack elements */
  87. /* convert a 'StackValue' to a 'TValue' */
  88. #define s2v(o) (&(o)->val)
  89. /*
  90. ** {==================================================================
  91. ** Nil
  92. ** ===================================================================
  93. */
  94. #define ttisnil(o) checktag((o), LUA_TNIL)
  95. /* macro defining a nil value */
  96. #define NILCONSTANT {NULL}, LUA_TNIL
  97. #define setnilvalue(obj) settt_(obj, LUA_TNIL)
  98. /* (address of) a fixed nil value */
  99. #define luaO_nilobject (&luaO_nilobject_)
  100. /*
  101. ** Variant tag, used only in tables to signal an empty slot
  102. ** (which might be different from a slot containing nil)
  103. */
  104. #define LUA_TEMPTY (LUA_TNIL | (1 << 4))
  105. #define ttisnilorempty(v) checktype((v), LUA_TNIL)
  106. #define isreallyempty(v) checktag((v), LUA_TEMPTY)
  107. #if defined(LUA_NILINTABLE)
  108. #define isempty(v) isreallyempty(v)
  109. #else /* By default, entries with any kind of nil are considered empty */
  110. #define isempty(v) ttisnilorempty(v)
  111. #endif
  112. /* macro defining an empty value */
  113. #define EMPTYCONSTANT {NULL}, LUA_TEMPTY
  114. /* mark an entry as empty */
  115. #define setempty(v) settt_(v, LUA_TEMPTY)
  116. /* }================================================================== */
  117. /*
  118. ** {==================================================================
  119. ** Booleans
  120. ** ===================================================================
  121. */
  122. #define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
  123. #define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
  124. #define bvalueraw(v) ((v).b)
  125. #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
  126. #define setbvalue(obj,x) \
  127. { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }
  128. /* }================================================================== */
  129. /*
  130. ** {==================================================================
  131. ** Threads
  132. ** ===================================================================
  133. */
  134. #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
  135. #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc))
  136. #define setthvalue(L,obj,x) \
  137. { TValue *io = (obj); lua_State *x_ = (x); \
  138. val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \
  139. checkliveness(L,io); }
  140. #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t)
  141. /* }================================================================== */
  142. /*
  143. ** {==================================================================
  144. ** Collectable Objects
  145. ** ===================================================================
  146. */
  147. /*
  148. ** Common Header for all collectable objects (in macro form, to be
  149. ** included in other objects)
  150. */
  151. #define CommonHeader struct GCObject *next; lu_byte tt; lu_byte marked
  152. /* Common type for all collectable objects */
  153. typedef struct GCObject {
  154. CommonHeader;
  155. } GCObject;
  156. /* Bit mark for collectable types */
  157. #define BIT_ISCOLLECTABLE (1 << 6)
  158. #define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
  159. /* mark a tag as collectable */
  160. #define ctb(t) ((t) | BIT_ISCOLLECTABLE)
  161. #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
  162. #define gcvalueraw(v) ((v).gc)
  163. #define setgcovalue(L,obj,x) \
  164. { TValue *io = (obj); GCObject *i_g=(x); \
  165. val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }
  166. /* }================================================================== */
  167. /*
  168. ** {==================================================================
  169. ** Numbers
  170. ** ===================================================================
  171. */
  172. /* Variant tags for numbers */
  173. #define LUA_TNUMFLT (LUA_TNUMBER | (1 << 4)) /* float numbers */
  174. #define LUA_TNUMINT (LUA_TNUMBER | (2 << 4)) /* integer numbers */
  175. #define ttisnumber(o) checktype((o), LUA_TNUMBER)
  176. #define ttisfloat(o) checktag((o), LUA_TNUMFLT)
  177. #define ttisinteger(o) checktag((o), LUA_TNUMINT)
  178. #define nvalue(o) check_exp(ttisnumber(o), \
  179. (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))
  180. #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n)
  181. #define ivalue(o) check_exp(ttisinteger(o), val_(o).i)
  182. #define fltvalueraw(v) ((v).n)
  183. #define ivalueraw(v) ((v).i)
  184. #define setfltvalue(obj,x) \
  185. { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }
  186. #define chgfltvalue(obj,x) \
  187. { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
  188. #define setivalue(obj,x) \
  189. { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }
  190. #define chgivalue(obj,x) \
  191. { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
  192. /* }================================================================== */
  193. /*
  194. ** {==================================================================
  195. ** Strings
  196. ** ===================================================================
  197. */
  198. /* Variant tags for strings */
  199. #define LUA_TSHRSTR (LUA_TSTRING | (1 << 4)) /* short strings */
  200. #define LUA_TLNGSTR (LUA_TSTRING | (2 << 4)) /* long strings */
  201. #define ttisstring(o) checktype((o), LUA_TSTRING)
  202. #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
  203. #define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
  204. #define tsvalueraw(v) (gco2ts((v).gc))
  205. #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc))
  206. #define setsvalue(L,obj,x) \
  207. { TValue *io = (obj); TString *x_ = (x); \
  208. val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \
  209. checkliveness(L,io); }
  210. /* set a string to the stack */
  211. #define setsvalue2s(L,o,s) setsvalue(L,s2v(o),s)
  212. /* set a string to a new object */
  213. #define setsvalue2n setsvalue
  214. /*
  215. ** Header for string value; string bytes follow the end of this structure
  216. ** (aligned according to 'UTString'; see next).
  217. */
  218. typedef struct TString {
  219. CommonHeader;
  220. lu_byte extra; /* reserved words for short strings; "has hash" for longs */
  221. lu_byte shrlen; /* length for short strings */
  222. unsigned int hash;
  223. union {
  224. size_t lnglen; /* length for long strings */
  225. struct TString *hnext; /* linked list for hash table */
  226. } u;
  227. } TString;
  228. /*
  229. ** Ensures that address after this type is always fully aligned.
  230. */
  231. typedef union UTString {
  232. LUAI_MAXALIGN; /* ensures maximum alignment for strings */
  233. TString tsv;
  234. } UTString;
  235. /*
  236. ** Get the actual string (array of bytes) from a 'TString'.
  237. ** (Access to 'extra' ensures that value is really a 'TString'.)
  238. */
  239. #define getstr(ts) \
  240. check_exp(sizeof((ts)->extra), cast_charp((ts)) + sizeof(UTString))
  241. /* get the actual string (array of bytes) from a Lua value */
  242. #define svalue(o) getstr(tsvalue(o))
  243. /* get string length from 'TString *s' */
  244. #define tsslen(s) ((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen)
  245. /* get string length from 'TValue *o' */
  246. #define vslen(o) tsslen(tsvalue(o))
  247. /* }================================================================== */
  248. /*
  249. ** {==================================================================
  250. ** Userdata
  251. ** ===================================================================
  252. */
  253. #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
  254. #define ttisfulluserdata(o) checktag((o), ctb(LUA_TUSERDATA))
  255. #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
  256. #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc))
  257. #define pvalueraw(v) ((v).p)
  258. #define setpvalue(obj,x) \
  259. { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
  260. #define setuvalue(L,obj,x) \
  261. { TValue *io = (obj); Udata *x_ = (x); \
  262. val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \
  263. checkliveness(L,io); }
  264. /* Ensures that addresses after this type are always fully aligned. */
  265. typedef union UValue {
  266. TValue uv;
  267. LUAI_MAXALIGN; /* ensures maximum alignment for udata bytes */
  268. } UValue;
  269. /*
  270. ** Header for userdata; memory area follows the end of this structure.
  271. */
  272. typedef struct Udata {
  273. CommonHeader;
  274. unsigned short nuvalue; /* number of user values */
  275. size_t len; /* number of bytes */
  276. struct Table *metatable;
  277. GCObject *gclist;
  278. UValue uv[1]; /* user values */
  279. } Udata;
  280. /* computes the offset of the memory area of a userdata */
  281. #define udatamemoffset(nuv) (sizeof(Udata) + (sizeof(UValue) * ((nuv) - 1)))
  282. /*
  283. ** Get the address of the memory block inside 'Udata'.
  284. */
  285. #define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue))
  286. /* computes the size of a userdata */
  287. #define sizeudata(nuv,nb) (udatamemoffset(nuv) + (nb))
  288. /* }================================================================== */
  289. /*
  290. ** {==================================================================
  291. ** Prototypes
  292. ** ===================================================================
  293. */
  294. /*
  295. ** Description of an upvalue for function prototypes
  296. */
  297. typedef struct Upvaldesc {
  298. TString *name; /* upvalue name (for debug information) */
  299. lu_byte instack; /* whether it is in stack (register) */
  300. lu_byte idx; /* index of upvalue (in stack or in outer function's list) */
  301. } Upvaldesc;
  302. /*
  303. ** Description of a local variable for function prototypes
  304. ** (used for debug information)
  305. */
  306. typedef struct LocVar {
  307. TString *varname;
  308. int startpc; /* first point where variable is active */
  309. int endpc; /* first point where variable is dead */
  310. } LocVar;
  311. /*
  312. ** Associates the absolute line source for a given instruction ('pc').
  313. ** The array 'lineinfo' gives, for each instruction, the difference in
  314. ** lines from the previous instruction. When that difference does not
  315. ** fit into a byte, Lua saves the absolute line for that instruction.
  316. ** (Lua also saves the absolute line periodically, to speed up the
  317. ** computation of a line number: we can use binary search in the
  318. ** absolute-line array, but we must traverse the 'lineinfo' array
  319. ** linearly to compute a line.)
  320. */
  321. typedef struct AbsLineInfo {
  322. int pc;
  323. int line;
  324. } AbsLineInfo;
  325. /*
  326. ** Function Prototypes
  327. */
  328. typedef struct Proto {
  329. CommonHeader;
  330. lu_byte numparams; /* number of fixed (named) parameters */
  331. lu_byte is_vararg;
  332. lu_byte maxstacksize; /* number of registers needed by this function */
  333. lu_byte cachemiss; /* count for successive misses for 'cache' field */
  334. int sizeupvalues; /* size of 'upvalues' */
  335. int sizek; /* size of 'k' */
  336. int sizecode;
  337. int sizelineinfo;
  338. int sizep; /* size of 'p' */
  339. int sizelocvars;
  340. int sizeabslineinfo; /* size of 'abslineinfo' */
  341. int linedefined; /* debug information */
  342. int lastlinedefined; /* debug information */
  343. TValue *k; /* constants used by the function */
  344. struct LClosure *cache; /* last-created closure with this prototype */
  345. Instruction *code; /* opcodes */
  346. struct Proto **p; /* functions defined inside the function */
  347. Upvaldesc *upvalues; /* upvalue information */
  348. ls_byte *lineinfo; /* information about source lines (debug information) */
  349. AbsLineInfo *abslineinfo; /* idem */
  350. LocVar *locvars; /* information about local variables (debug information) */
  351. TString *source; /* used for debug information */
  352. GCObject *gclist;
  353. } Proto;
  354. /* }================================================================== */
  355. /*
  356. ** {==================================================================
  357. ** Closures
  358. ** ===================================================================
  359. */
  360. /* Variant tags for functions */
  361. #define LUA_TLCL (LUA_TFUNCTION | (1 << 4)) /* Lua closure */
  362. #define LUA_TLCF (LUA_TFUNCTION | (2 << 4)) /* light C function */
  363. #define LUA_TCCL (LUA_TFUNCTION | (3 << 4)) /* C closure */
  364. #define ttisfunction(o) checktype(o, LUA_TFUNCTION)
  365. #define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TLCL)
  366. #define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
  367. #define ttislcf(o) checktag((o), LUA_TLCF)
  368. #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
  369. #define isLfunction(o) ttisLclosure(o)
  370. #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc))
  371. #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc))
  372. #define fvalue(o) check_exp(ttislcf(o), val_(o).f)
  373. #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc))
  374. #define fvalueraw(v) ((v).f)
  375. #define setclLvalue(L,obj,x) \
  376. { TValue *io = (obj); LClosure *x_ = (x); \
  377. val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \
  378. checkliveness(L,io); }
  379. #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl)
  380. #define setfvalue(obj,x) \
  381. { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
  382. #define setclCvalue(L,obj,x) \
  383. { TValue *io = (obj); CClosure *x_ = (x); \
  384. val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \
  385. checkliveness(L,io); }
  386. /*
  387. ** Upvalues for Lua closures
  388. */
  389. typedef struct UpVal {
  390. CommonHeader;
  391. TValue *v; /* points to stack or to its own value */
  392. union {
  393. struct { /* (when open) */
  394. struct UpVal *next; /* linked list */
  395. struct UpVal **previous;
  396. } open;
  397. TValue value; /* the value (when closed) */
  398. } u;
  399. } UpVal;
  400. #define ClosureHeader \
  401. CommonHeader; lu_byte nupvalues; GCObject *gclist
  402. typedef struct CClosure {
  403. ClosureHeader;
  404. lua_CFunction f;
  405. TValue upvalue[1]; /* list of upvalues */
  406. } CClosure;
  407. typedef struct LClosure {
  408. ClosureHeader;
  409. struct Proto *p;
  410. UpVal *upvals[1]; /* list of upvalues */
  411. } LClosure;
  412. typedef union Closure {
  413. CClosure c;
  414. LClosure l;
  415. } Closure;
  416. #define getproto(o) (clLvalue(o)->p)
  417. /* }================================================================== */
  418. /*
  419. ** {==================================================================
  420. ** Tables
  421. ** ===================================================================
  422. */
  423. #define ttistable(o) checktag((o), ctb(LUA_TTABLE))
  424. #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc))
  425. #define sethvalue(L,obj,x) \
  426. { TValue *io = (obj); Table *x_ = (x); \
  427. val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \
  428. checkliveness(L,io); }
  429. #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h)
  430. /*
  431. ** Nodes for Hash tables: A pack of two TValue's (key-value pairs)
  432. ** plus a 'next' field to link colliding entries. The distribution
  433. ** of the key's fields ('key_tt' and 'key_val') not forming a proper
  434. ** 'TValue' allows for a smaller size for 'Node' both in 4-byte
  435. ** and 8-byte alignments.
  436. */
  437. typedef union Node {
  438. struct NodeKey {
  439. TValuefields; /* fields for value */
  440. lu_byte key_tt; /* key type */
  441. int next; /* for chaining */
  442. Value key_val; /* key value */
  443. } u;
  444. TValue i_val; /* direct access to node's value as a proper 'TValue' */
  445. } Node;
  446. /* copy a value into a key */
  447. #define setnodekey(L,node,obj) \
  448. { Node *n_=(node); const TValue *io_=(obj); \
  449. n_->u.key_val = io_->value_; n_->u.key_tt = io_->tt_; \
  450. (void)L; checkliveness(L,io_); }
  451. /* copy a value from a key */
  452. #define getnodekey(L,obj,node) \
  453. { TValue *io_=(obj); const Node *n_=(node); \
  454. io_->value_ = n_->u.key_val; io_->tt_ = n_->u.key_tt; \
  455. (void)L; checkliveness(L,io_); }
  456. typedef struct Table {
  457. CommonHeader;
  458. lu_byte flags; /* 1<<p means tagmethod(p) is not present */
  459. lu_byte lsizenode; /* log2 of size of 'node' array */
  460. unsigned int sizearray; /* size of 'array' array */
  461. TValue *array; /* array part */
  462. Node *node;
  463. Node *lastfree; /* any free position is before this position */
  464. struct Table *metatable;
  465. GCObject *gclist;
  466. } Table;
  467. /*
  468. ** Macros to manipulate keys inserted in nodes
  469. */
  470. #define keytt(node) ((node)->u.key_tt)
  471. #define keyval(node) ((node)->u.key_val)
  472. #define keyisnil(node) (keytt(node) == LUA_TNIL)
  473. #define keyisinteger(node) (keytt(node) == LUA_TNUMINT)
  474. #define keyival(node) (keyval(node).i)
  475. #define keyisshrstr(node) (keytt(node) == ctb(LUA_TSHRSTR))
  476. #define keystrval(node) (gco2ts(keyval(node).gc))
  477. #define setnilkey(node) (keytt(node) = LUA_TNIL)
  478. #define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE)
  479. #define gckey(n) (keyval(n).gc)
  480. #define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL)
  481. /*
  482. ** Use a "nil table" to mark dead keys in a table. Those keys serve
  483. ** to keep space for removed entries, which may still be part of
  484. ** chains. Note that the 'keytt' does not have the BIT_ISCOLLECTABLE
  485. ** set, so these values are considered not collectable and are different
  486. ** from any valid value.
  487. */
  488. #define setdeadkey(n) (keytt(n) = LUA_TTABLE, gckey(n) = NULL)
  489. /* }================================================================== */
  490. /*
  491. ** 'module' operation for hashing (size is always a power of 2)
  492. */
  493. #define lmod(s,size) \
  494. (check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1)))))
  495. #define twoto(x) (1<<(x))
  496. #define sizenode(t) (twoto((t)->lsizenode))
  497. LUAI_DDEC const TValue luaO_nilobject_;
  498. /* size of buffer for 'luaO_utf8esc' function */
  499. #define UTF8BUFFSZ 8
  500. LUAI_FUNC int luaO_int2fb (unsigned int x);
  501. LUAI_FUNC int luaO_fb2int (int x);
  502. LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);
  503. LUAI_FUNC int luaO_ceillog2 (unsigned int x);
  504. LUAI_FUNC int luaO_rawarith (lua_State *L, int op, const TValue *p1,
  505. const TValue *p2, TValue *res);
  506. LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,
  507. const TValue *p2, StkId res);
  508. LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o);
  509. LUAI_FUNC int luaO_hexavalue (int c);
  510. LUAI_FUNC void luaO_tostring (lua_State *L, TValue *obj);
  511. LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
  512. va_list argp);
  513. LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
  514. LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
  515. #endif