ltests.c
Go to the documentation of this file.
1 /*
2 ** $Id: ltests.c $
3 ** Internal Module for Debugging of the Lua Implementation
4 ** See Copyright Notice in lua.h
5 */
6 
7 #define ltests_c
8 #define LUA_CORE
9 
10 #include "lprefix.h"
11 
12 
13 #include <limits.h>
14 #include <setjmp.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 
19 #include "lua.h"
20 
21 #include "lapi.h"
22 #include "lauxlib.h"
23 #include "lcode.h"
24 #include "lctype.h"
25 #include "ldebug.h"
26 #include "ldo.h"
27 #include "lfunc.h"
28 #include "lmem.h"
29 #include "lopcodes.h"
30 #include "lopnames.h"
31 #include "lstate.h"
32 #include "lstring.h"
33 #include "ltable.h"
34 #include "lualib.h"
35 
36 
37 
38 /*
39 ** The whole module only makes sense with LUA_DEBUG on
40 */
41 #if defined(LUA_DEBUG)
42 
43 
44 void *l_Trick = 0;
45 
46 
47 #define obj_at(L,k) s2v(L->ci->func + (k))
48 
49 
50 static int runC (lua_State *L, lua_State *L1, const char *pc);
51 
52 
53 static void setnameval (lua_State *L, const char *name, int val) {
54  lua_pushinteger(L, val);
55  lua_setfield(L, -2, name);
56 }
57 
58 
59 static void pushobject (lua_State *L, const TValue *o) {
60  setobj2s(L, L->top, o);
61  api_incr_top(L);
62 }
63 
64 
65 static void badexit (const char *fmt, const char *s1, const char *s2) {
66  fprintf(stderr, fmt, s1);
67  if (s2)
68  fprintf(stderr, "extra info: %s\n", s2);
69  /* avoid assertion failures when exiting */
71  exit(EXIT_FAILURE);
72 }
73 
74 
75 static int tpanic (lua_State *L) {
76  const char *msg = lua_tostring(L, -1);
77  if (msg == NULL) msg = "error object is not a string";
78  return (badexit("PANIC: unprotected error in call to Lua API (%s)\n",
79  msg, NULL),
80  0); /* do not return to Lua */
81 }
82 
83 
84 /*
85 ** Warning function for tests. First, it concatenates all parts of
86 ** a warning in buffer 'buff'. Then, it has three modes:
87 ** - 0.normal: messages starting with '#' are shown on standard output;
88 ** - other messages abort the tests (they represent real warning
89 ** conditions; the standard tests should not generate these conditions
90 ** unexpectedly);
91 ** - 1.allow: all messages are shown;
92 ** - 2.store: all warnings go to the global '_WARN';
93 */
94 static void warnf (void *ud, const char *msg, int tocont) {
95  lua_State *L = cast(lua_State *, ud);
96  static char buff[200] = ""; /* should be enough for tests... */
97  static int onoff = 0;
98  static int mode = 0; /* start in normal mode */
99  static int lasttocont = 0;
100  if (!lasttocont && !tocont && *msg == '@') { /* control message? */
101  if (buff[0] != '\0')
102  badexit("Control warning during warning: %s\naborting...\n", msg, buff);
103  if (strcmp(msg, "@off") == 0)
104  onoff = 0;
105  else if (strcmp(msg, "@on") == 0)
106  onoff = 1;
107  else if (strcmp(msg, "@normal") == 0)
108  mode = 0;
109  else if (strcmp(msg, "@allow") == 0)
110  mode = 1;
111  else if (strcmp(msg, "@store") == 0)
112  mode = 2;
113  else
114  badexit("Invalid control warning in test mode: %s\naborting...\n",
115  msg, NULL);
116  return;
117  }
118  lasttocont = tocont;
119  if (strlen(msg) >= sizeof(buff) - strlen(buff))
120  badexit("warnf-buffer overflow (%s)\n", msg, buff);
121  strcat(buff, msg); /* add new message to current warning */
122  if (!tocont) { /* message finished? */
123  lua_unlock(L);
124  lua_getglobal(L, "_WARN");
125  if (!lua_toboolean(L, -1))
126  lua_pop(L, 1); /* ok, no previous unexpected warning */
127  else {
128  badexit("Unhandled warning in store mode: %s\naborting...\n",
129  lua_tostring(L, -1), buff);
130  }
131  lua_lock(L);
132  switch (mode) {
133  case 0: { /* normal */
134  if (buff[0] != '#' && onoff) /* unexpected warning? */
135  badexit("Unexpected warning in test mode: %s\naborting...\n",
136  buff, NULL);
137  } /* FALLTHROUGH */
138  case 1: { /* allow */
139  if (onoff)
140  fprintf(stderr, "Lua warning: %s\n", buff); /* print warning */
141  break;
142  }
143  case 2: { /* store */
144  lua_unlock(L);
145  lua_pushstring(L, buff);
146  lua_setglobal(L, "_WARN"); /* assign message to global '_WARN' */
147  lua_lock(L);
148  break;
149  }
150  }
151  buff[0] = '\0'; /* prepare buffer for next warning */
152  }
153 }
154 
155 
156 /*
157 ** {======================================================================
158 ** Controlled version for realloc.
159 ** =======================================================================
160 */
161 
162 #define MARK 0x55 /* 01010101 (a nice pattern) */
163 
164 typedef union Header {
166  struct {
167  size_t size;
168  int type;
169  } d;
170 } Header;
171 
172 
173 #if !defined(EXTERNMEMCHECK)
174 
175 /* full memory check */
176 #define MARKSIZE 16 /* size of marks after each block */
177 #define fillmem(mem,size) memset(mem, -MARK, size)
178 
179 #else
180 
181 /* external memory check: don't do it twice */
182 #define MARKSIZE 0
183 #define fillmem(mem,size) /* empty */
184 
185 #endif
186 
187 
189  {0, 0UL, 0UL, 0UL, 0UL, (~0UL),
190  {0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL}};
191 
192 
193 static void freeblock (Memcontrol *mc, Header *block) {
194  if (block) {
195  size_t size = block->d.size;
196  int i;
197  for (i = 0; i < MARKSIZE; i++) /* check marks after block */
198  lua_assert(*(cast_charp(block + 1) + size + i) == MARK);
199  mc->objcount[block->d.type]--;
200  fillmem(block, sizeof(Header) + size + MARKSIZE); /* erase block */
201  free(block); /* actually free block */
202  mc->numblocks--; /* update counts */
203  mc->total -= size;
204  }
205 }
206 
207 
208 void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) {
209  Memcontrol *mc = cast(Memcontrol *, ud);
210  Header *block = cast(Header *, b);
211  int type;
212  if (mc->memlimit == 0) { /* first time? */
213  char *limit = getenv("MEMLIMIT"); /* initialize memory limit */
214  mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX;
215  }
216  if (block == NULL) {
217  type = (oldsize < LUA_NUMTAGS) ? oldsize : 0;
218  oldsize = 0;
219  }
220  else {
221  block--; /* go to real header */
222  type = block->d.type;
223  lua_assert(oldsize == block->d.size);
224  }
225  if (size == 0) {
226  freeblock(mc, block);
227  return NULL;
228  }
229  if (mc->failnext) {
230  mc->failnext = 0;
231  return NULL; /* fake a single memory allocation error */
232  }
233  if (mc->countlimit != ~0UL && size != oldsize) { /* count limit in use? */
234  if (mc->countlimit == 0)
235  return NULL; /* fake a memory allocation error */
236  mc->countlimit--;
237  }
238  if (size > oldsize && mc->total+size-oldsize > mc->memlimit)
239  return NULL; /* fake a memory allocation error */
240  else {
241  Header *newblock;
242  int i;
243  size_t commonsize = (oldsize < size) ? oldsize : size;
244  size_t realsize = sizeof(Header) + size + MARKSIZE;
245  if (realsize < size) return NULL; /* arithmetic overflow! */
246  newblock = cast(Header *, malloc(realsize)); /* alloc a new block */
247  if (newblock == NULL)
248  return NULL; /* really out of memory? */
249  if (block) {
250  memcpy(newblock + 1, block + 1, commonsize); /* copy old contents */
251  freeblock(mc, block); /* erase (and check) old copy */
252  }
253  /* initialize new part of the block with something weird */
254  fillmem(cast_charp(newblock + 1) + commonsize, size - commonsize);
255  /* initialize marks after block */
256  for (i = 0; i < MARKSIZE; i++)
257  *(cast_charp(newblock + 1) + size + i) = MARK;
258  newblock->d.size = size;
259  newblock->d.type = type;
260  mc->total += size;
261  if (mc->total > mc->maxmem)
262  mc->maxmem = mc->total;
263  mc->numblocks++;
264  mc->objcount[type]++;
265  return newblock + 1;
266  }
267 }
268 
269 
270 /* }====================================================================== */
271 
272 
273 
274 /*
275 ** {======================================================
276 ** Functions to check memory consistency
277 ** =======================================================
278 */
279 
280 
281 /*
282 ** Check GC invariants. For incremental mode, a black object cannot
283 ** point to a white one. For generational mode, really old objects
284 ** cannot point to young objects. Both old1 and touched2 objects
285 ** cannot point to new objects (but can point to survivals).
286 ** (Threads and open upvalues, despite being marked "really old",
287 ** continue to be visited in all collections, and therefore can point to
288 ** new objects. They, and only they, are old but gray.)
289 */
290 static int testobjref1 (global_State *g, GCObject *f, GCObject *t) {
291  if (isdead(g,t)) return 0;
292  if (issweepphase(g))
293  return 1; /* no invariants */
294  else if (g->gckind == KGC_INC)
295  return !(isblack(f) && iswhite(t)); /* basic incremental invariant */
296  else { /* generational mode */
297  if ((getage(f) == G_OLD && isblack(f)) && !isold(t))
298  return 0;
299  if (((getage(f) == G_OLD1 || getage(f) == G_TOUCHED2) && isblack(f)) &&
300  getage(t) == G_NEW)
301  return 0;
302  return 1;
303  }
304 }
305 
306 
307 static void printobj (global_State *g, GCObject *o) {
308  printf("||%s(%p)-%c%c(%02X)||",
309  ttypename(novariant(o->tt)), (void *)o,
310  isdead(g,o) ? 'd' : isblack(o) ? 'b' : iswhite(o) ? 'w' : 'g',
311  "ns01oTt"[getage(o)], o->marked);
312  if (o->tt == LUA_VSHRSTR || o->tt == LUA_VLNGSTR)
313  printf(" '%s'", getstr(gco2ts(o)));
314 }
315 
316 
317 void lua_printobj (lua_State *L, struct GCObject *o) {
318  printobj(G(L), o);
319 }
320 
321 static int testobjref (global_State *g, GCObject *f, GCObject *t) {
322  int r1 = testobjref1(g, f, t);
323  if (!r1) {
324  printf("%d(%02X) - ", g->gcstate, g->currentwhite);
325  printobj(g, f);
326  printf(" -> ");
327  printobj(g, t);
328  printf("\n");
329  }
330  return r1;
331 }
332 
333 #define checkobjref(g,f,t) \
334  { if (t) lua_longassert(testobjref(g,f,obj2gco(t))); }
335 
336 
337 static void checkvalref (global_State *g, GCObject *f, const TValue *t) {
339  (righttt(t) && testobjref(g, f, gcvalue(t))));
340 }
341 
342 
343 static void checktable (global_State *g, Table *h) {
344  unsigned int i;
345  unsigned int asize = luaH_realasize(h);
346  Node *n, *limit = gnode(h, sizenode(h));
347  GCObject *hgc = obj2gco(h);
348  checkobjref(g, hgc, h->metatable);
349  for (i = 0; i < asize; i++)
350  checkvalref(g, hgc, &h->array[i]);
351  for (n = gnode(h, 0); n < limit; n++) {
352  if (!isempty(gval(n))) {
353  TValue k;
354  getnodekey(g->mainthread, &k, n);
355  lua_assert(!keyisnil(n));
356  checkvalref(g, hgc, &k);
357  checkvalref(g, hgc, gval(n));
358  }
359  }
360 }
361 
362 
363 static void checkudata (global_State *g, Udata *u) {
364  int i;
365  GCObject *hgc = obj2gco(u);
366  checkobjref(g, hgc, u->metatable);
367  for (i = 0; i < u->nuvalue; i++)
368  checkvalref(g, hgc, &u->uv[i].uv);
369 }
370 
371 
372 /*
373 ** All marks are conditional because a GC may happen while the
374 ** prototype is still being created
375 */
376 static void checkproto (global_State *g, Proto *f) {
377  int i;
378  GCObject *fgc = obj2gco(f);
379  checkobjref(g, fgc, f->source);
380  for (i=0; i<f->sizek; i++) {
381  if (ttisstring(f->k + i))
382  checkobjref(g, fgc, tsvalue(f->k + i));
383  }
384  for (i=0; i<f->sizeupvalues; i++)
385  checkobjref(g, fgc, f->upvalues[i].name);
386  for (i=0; i<f->sizep; i++)
387  checkobjref(g, fgc, f->p[i]);
388  for (i=0; i<f->sizelocvars; i++)
389  checkobjref(g, fgc, f->locvars[i].varname);
390 }
391 
392 
393 static void checkCclosure (global_State *g, CClosure *cl) {
394  GCObject *clgc = obj2gco(cl);
395  int i;
396  for (i = 0; i < cl->nupvalues; i++)
397  checkvalref(g, clgc, &cl->upvalue[i]);
398 }
399 
400 
401 static void checkLclosure (global_State *g, LClosure *cl) {
402  GCObject *clgc = obj2gco(cl);
403  int i;
404  checkobjref(g, clgc, cl->p);
405  for (i=0; i<cl->nupvalues; i++) {
406  UpVal *uv = cl->upvals[i];
407  if (uv) {
408  checkobjref(g, clgc, uv);
409  if (!upisopen(uv))
410  checkvalref(g, obj2gco(uv), uv->v);
411  }
412  }
413 }
414 
415 
416 static int lua_checkpc (CallInfo *ci) {
417  if (!isLua(ci)) return 1;
418  else {
419  StkId f = ci->func;
420  Proto *p = clLvalue(s2v(f))->p;
421  return p->code <= ci->u.l.savedpc &&
422  ci->u.l.savedpc <= p->code + p->sizecode;
423  }
424 }
425 
426 
427 static void checkstack (global_State *g, lua_State *L1) {
428  StkId o;
429  CallInfo *ci;
430  UpVal *uv;
431  lua_assert(!isdead(g, L1));
432  if (L1->stack == NULL) { /* incomplete thread? */
433  lua_assert(L1->stacksize == 0 && L1->openupval == NULL &&
434  L1->ci == NULL);
435  return;
436  }
437  for (uv = L1->openupval; uv != NULL; uv = uv->u.open.next)
438  lua_assert(upisopen(uv)); /* must be open */
439  for (ci = L1->ci; ci != NULL; ci = ci->previous) {
440  lua_assert(ci->top <= L1->stack_last);
441  lua_assert(lua_checkpc(ci));
442  }
443  for (o = L1->stack; o < L1->stack_last + EXTRA_STACK; o++)
444  checkliveness(L1, s2v(o)); /* entire stack must have valid values */
445 }
446 
447 
448 static void checkrefs (global_State *g, GCObject *o) {
449  switch (o->tt) {
450  case LUA_VUSERDATA: {
451  checkudata(g, gco2u(o));
452  break;
453  }
454  case LUA_VUPVAL: {
455  checkvalref(g, o, gco2upv(o)->v);
456  break;
457  }
458  case LUA_VTABLE: {
459  checktable(g, gco2t(o));
460  break;
461  }
462  case LUA_VTHREAD: {
463  checkstack(g, gco2th(o));
464  break;
465  }
466  case LUA_VLCL: {
467  checkLclosure(g, gco2lcl(o));
468  break;
469  }
470  case LUA_VCCL: {
471  checkCclosure(g, gco2ccl(o));
472  break;
473  }
474  case LUA_VPROTO: {
475  checkproto(g, gco2p(o));
476  break;
477  }
478  case LUA_VSHRSTR:
479  case LUA_VLNGSTR: {
480  lua_assert(!isgray(o)); /* strings are never gray */
481  break;
482  }
483  default: lua_assert(0);
484  }
485 }
486 
487 
488 /*
489 ** Check consistency of an object:
490 ** - Dead objects can only happen in the 'allgc' list during a sweep
491 ** phase (controlled by the caller through 'maybedead').
492 ** - During pause, all objects must be white.
493 ** - In generational mode:
494 ** * objects must be old enough for their lists ('listage').
495 ** * old objects cannot be white.
496 ** * old objects must be black, except for 'touched1', 'old0',
497 ** threads, and open upvalues.
498 */
499 static void checkobject (global_State *g, GCObject *o, int maybedead,
500  int listage) {
501  if (isdead(g, o))
502  lua_assert(maybedead);
503  else {
504  lua_assert(g->gcstate != GCSpause || iswhite(o));
505  if (g->gckind == KGC_GEN) { /* generational mode? */
506  lua_assert(getage(o) >= listage);
507  lua_assert(!iswhite(o) || !isold(o));
508  if (isold(o)) {
509  lua_assert(isblack(o) ||
510  getage(o) == G_TOUCHED1 ||
511  getage(o) == G_OLD0 ||
512  o->tt == LUA_VTHREAD ||
513  (o->tt == LUA_VUPVAL && upisopen(gco2upv(o))));
514  }
515  }
516  checkrefs(g, o);
517  }
518 }
519 
520 
521 static lu_mem checkgraylist (global_State *g, GCObject *o) {
522  int total = 0; /* count number of elements in the list */
523  ((void)g); /* better to keep it available if we need to print an object */
524  while (o) {
525  lua_assert(!!isgray(o) ^ (getage(o) == G_TOUCHED2));
526  //lua_assert(isgray(o) || getage(o) == G_TOUCHED2);
527  lua_assert(!testbit(o->marked, TESTBIT));
528  if (keepinvariant(g))
529  l_setbit(o->marked, TESTBIT); /* mark that object is in a gray list */
530  total++;
531  switch (o->tt) {
532  case LUA_VTABLE: o = gco2t(o)->gclist; break;
533  case LUA_VLCL: o = gco2lcl(o)->gclist; break;
534  case LUA_VCCL: o = gco2ccl(o)->gclist; break;
535  case LUA_VTHREAD: o = gco2th(o)->gclist; break;
536  case LUA_VPROTO: o = gco2p(o)->gclist; break;
537  case LUA_VUSERDATA:
538  lua_assert(gco2u(o)->nuvalue > 0);
539  o = gco2u(o)->gclist;
540  break;
541  default: lua_assert(0); /* other objects cannot be in a gray list */
542  }
543  }
544  return total;
545 }
546 
547 
548 /*
549 ** Check objects in gray lists.
550 */
551 static lu_mem checkgrays (global_State *g) {
552  int total = 0; /* count number of elements in all lists */
553  if (!keepinvariant(g)) return total;
554  total += checkgraylist(g, g->gray);
555  total += checkgraylist(g, g->grayagain);
556  total += checkgraylist(g, g->weak);
557  total += checkgraylist(g, g->allweak);
558  total += checkgraylist(g, g->ephemeron);
559  return total;
560 }
561 
562 
563 /*
564 ** Check whether 'o' should be in a gray list. If so, increment
565 ** 'count' and check its TESTBIT. (It must have been previously set by
566 ** 'checkgraylist'.)
567 */
568 static void incifingray (global_State *g, GCObject *o, lu_mem *count) {
569  if (!keepinvariant(g))
570  return; /* gray lists not being kept in these phases */
571  if (o->tt == LUA_VUPVAL) {
572  /* only open upvalues can be gray */
573  lua_assert(!isgray(o) || upisopen(gco2upv(o)));
574  return; /* upvalues are never in gray lists */
575  }
576  /* these are the ones that must be in gray lists */
577  if (isgray(o) || getage(o) == G_TOUCHED2) {
578  (*count)++;
579  lua_assert(testbit(o->marked, TESTBIT));
580  resetbit(o->marked, TESTBIT); /* prepare for next cycle */
581  }
582 }
583 
584 
585 static lu_mem checklist (global_State *g, int maybedead, int tof,
586  GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) {
587  GCObject *o;
588  lu_mem total = 0; /* number of object that should be in gray lists */
589  for (o = newl; o != survival; o = o->next) {
590  checkobject(g, o, maybedead, G_NEW);
591  incifingray(g, o, &total);
592  lua_assert(!tof == !tofinalize(o));
593  }
594  for (o = survival; o != old; o = o->next) {
595  checkobject(g, o, 0, G_SURVIVAL);
596  incifingray(g, o, &total);
597  lua_assert(!tof == !tofinalize(o));
598  }
599  for (o = old; o != reallyold; o = o->next) {
600  checkobject(g, o, 0, G_OLD1);
601  incifingray(g, o, &total);
602  lua_assert(!tof == !tofinalize(o));
603  }
604  for (o = reallyold; o != NULL; o = o->next) {
605  checkobject(g, o, 0, G_OLD);
606  incifingray(g, o, &total);
607  lua_assert(!tof == !tofinalize(o));
608  }
609  return total;
610 }
611 
612 
613 int lua_checkmemory (lua_State *L) {
614  global_State *g = G(L);
615  GCObject *o;
616  int maybedead;
617  lu_mem totalin; /* total of objects that are in gray lists */
618  lu_mem totalshould; /* total of objects that should be in gray lists */
619  if (keepinvariant(g)) {
622  }
623  lua_assert(!isdead(g, gcvalue(&g->l_registry)));
624  lua_assert(g->sweepgc == NULL || issweepphase(g));
625  totalin = checkgrays(g);
626 
627  /* check 'fixedgc' list */
628  for (o = g->fixedgc; o != NULL; o = o->next) {
629  lua_assert(o->tt == LUA_VSHRSTR && isgray(o) && getage(o) == G_OLD);
630  }
631 
632  /* check 'allgc' list */
633  maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpallgc);
634  totalshould = checklist(g, maybedead, 0, g->allgc,
635  g->survival, g->old1, g->reallyold);
636 
637  /* check 'finobj' list */
638  totalshould += checklist(g, 0, 1, g->finobj,
639  g->finobjsur, g->finobjold1, g->finobjrold);
640 
641  /* check 'tobefnz' list */
642  for (o = g->tobefnz; o != NULL; o = o->next) {
643  checkobject(g, o, 0, G_NEW);
644  incifingray(g, o, &totalshould);
646  lua_assert(o->tt == LUA_VUSERDATA || o->tt == LUA_VTABLE);
647  }
648  if (keepinvariant(g))
649  lua_assert(totalin == totalshould);
650  return 0;
651 }
652 
653 /* }====================================================== */
654 
655 
656 
657 /*
658 ** {======================================================
659 ** Disassembler
660 ** =======================================================
661 */
662 
663 
664 static char *buildop (Proto *p, int pc, char *buff) {
665  char *obuff = buff;
666  Instruction i = p->code[pc];
667  OpCode o = GET_OPCODE(i);
668  const char *name = opnames[o];
669  int line = luaG_getfuncline(p, pc);
670  int lineinfo = (p->lineinfo != NULL) ? p->lineinfo[pc] : 0;
671  if (lineinfo == ABSLINEINFO)
672  buff += sprintf(buff, "(__");
673  else
674  buff += sprintf(buff, "(%2d", lineinfo);
675  buff += sprintf(buff, " - %4d) %4d - ", line, pc);
676  switch (getOpMode(o)) {
677  case iABC:
678  sprintf(buff, "%-12s%4d %4d %4d%s", name,
679  GETARG_A(i), GETARG_B(i), GETARG_C(i),
680  GETARG_k(i) ? " (k)" : "");
681  break;
682  case iABx:
683  sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_Bx(i));
684  break;
685  case iAsBx:
686  sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_sBx(i));
687  break;
688  case iAx:
689  sprintf(buff, "%-12s%4d", name, GETARG_Ax(i));
690  break;
691  case isJ:
692  sprintf(buff, "%-12s%4d", name, GETARG_sJ(i));
693  break;
694  }
695  return obuff;
696 }
697 
698 
699 #if 0
700 void luaI_printcode (Proto *pt, int size) {
701  int pc;
702  for (pc=0; pc<size; pc++) {
703  char buff[100];
704  printf("%s\n", buildop(pt, pc, buff));
705  }
706  printf("-------\n");
707 }
708 
709 
710 void luaI_printinst (Proto *pt, int pc) {
711  char buff[100];
712  printf("%s\n", buildop(pt, pc, buff));
713 }
714 #endif
715 
716 
717 static int listcode (lua_State *L) {
718  int pc;
719  Proto *p;
720  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
721  1, "Lua function expected");
722  p = getproto(obj_at(L, 1));
723  lua_newtable(L);
724  setnameval(L, "maxstack", p->maxstacksize);
725  setnameval(L, "numparams", p->numparams);
726  for (pc=0; pc<p->sizecode; pc++) {
727  char buff[100];
728  lua_pushinteger(L, pc+1);
729  lua_pushstring(L, buildop(p, pc, buff));
730  lua_settable(L, -3);
731  }
732  return 1;
733 }
734 
735 
736 static int printcode (lua_State *L) {
737  int pc;
738  Proto *p;
739  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
740  1, "Lua function expected");
741  p = getproto(obj_at(L, 1));
742  printf("maxstack: %d\n", p->maxstacksize);
743  printf("numparams: %d\n", p->numparams);
744  for (pc=0; pc<p->sizecode; pc++) {
745  char buff[100];
746  printf("%s\n", buildop(p, pc, buff));
747  }
748  return 0;
749 }
750 
751 
752 static int listk (lua_State *L) {
753  Proto *p;
754  int i;
755  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
756  1, "Lua function expected");
757  p = getproto(obj_at(L, 1));
758  lua_createtable(L, p->sizek, 0);
759  for (i=0; i<p->sizek; i++) {
760  pushobject(L, p->k+i);
761  lua_rawseti(L, -2, i+1);
762  }
763  return 1;
764 }
765 
766 
767 static int listabslineinfo (lua_State *L) {
768  Proto *p;
769  int i;
770  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
771  1, "Lua function expected");
772  p = getproto(obj_at(L, 1));
773  luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info");
774  lua_createtable(L, 2 * p->sizeabslineinfo, 0);
775  for (i=0; i < p->sizeabslineinfo; i++) {
776  lua_pushinteger(L, p->abslineinfo[i].pc);
777  lua_rawseti(L, -2, 2 * i + 1);
778  lua_pushinteger(L, p->abslineinfo[i].line);
779  lua_rawseti(L, -2, 2 * i + 2);
780  }
781  return 1;
782 }
783 
784 
785 static int listlocals (lua_State *L) {
786  Proto *p;
787  int pc = cast_int(luaL_checkinteger(L, 2)) - 1;
788  int i = 0;
789  const char *name;
790  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
791  1, "Lua function expected");
792  p = getproto(obj_at(L, 1));
793  while ((name = luaF_getlocalname(p, ++i, pc)) != NULL)
794  lua_pushstring(L, name);
795  return i-1;
796 }
797 
798 /* }====================================================== */
799 
800 
801 
802 static void printstack (lua_State *L) {
803  int i;
804  int n = lua_gettop(L);
805  printf("stack: >>\n");
806  for (i = 1; i <= n; i++) {
807  printf("%3d: %s\n", i, luaL_tolstring(L, i, NULL));
808  lua_pop(L, 1);
809  }
810  printf("<<\n");
811 }
812 
813 
814 static int get_limits (lua_State *L) {
815  lua_createtable(L, 0, 6);
816  setnameval(L, "IS32INT", LUAI_IS32INT);
817  setnameval(L, "MAXARG_Ax", MAXARG_Ax);
818  setnameval(L, "MAXARG_Bx", MAXARG_Bx);
819  setnameval(L, "OFFSET_sBx", OFFSET_sBx);
820  setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
821  setnameval(L, "NUM_OPCODES", NUM_OPCODES);
822  return 1;
823 }
824 
825 
826 static int mem_query (lua_State *L) {
827  if (lua_isnone(L, 1)) {
828  lua_pushinteger(L, l_memcontrol.total);
829  lua_pushinteger(L, l_memcontrol.numblocks);
830  lua_pushinteger(L, l_memcontrol.maxmem);
831  return 3;
832  }
833  else if (lua_isnumber(L, 1)) {
834  unsigned long limit = cast(unsigned long, luaL_checkinteger(L, 1));
835  if (limit == 0) limit = ULONG_MAX;
836  l_memcontrol.memlimit = limit;
837  return 0;
838  }
839  else {
840  const char *t = luaL_checkstring(L, 1);
841  int i;
842  for (i = LUA_NUMTAGS - 1; i >= 0; i--) {
843  if (strcmp(t, ttypename(i)) == 0) {
844  lua_pushinteger(L, l_memcontrol.objcount[i]);
845  return 1;
846  }
847  }
848  return luaL_error(L, "unknown type '%s'", t);
849  }
850 }
851 
852 
853 static int alloc_count (lua_State *L) {
854  if (lua_isnone(L, 1))
855  l_memcontrol.countlimit = ~0L;
856  else
857  l_memcontrol.countlimit = luaL_checkinteger(L, 1);
858  return 0;
859 }
860 
861 
862 static int alloc_failnext (lua_State *L) {
863  UNUSED(L);
864  l_memcontrol.failnext = 1;
865  return 0;
866 }
867 
868 
869 static int settrick (lua_State *L) {
870  if (ttisnil(obj_at(L, 1)))
871  l_Trick = NULL;
872  else
873  l_Trick = gcvalue(obj_at(L, 1));
874  return 0;
875 }
876 
877 
878 static int gc_color (lua_State *L) {
879  TValue *o;
880  luaL_checkany(L, 1);
881  o = obj_at(L, 1);
882  if (!iscollectable(o))
883  lua_pushstring(L, "no collectable");
884  else {
885  GCObject *obj = gcvalue(o);
886  lua_pushstring(L, isdead(G(L), obj) ? "dead" :
887  iswhite(obj) ? "white" :
888  isblack(obj) ? "black" : "gray");
889  }
890  return 1;
891 }
892 
893 
894 static int gc_age (lua_State *L) {
895  TValue *o;
896  luaL_checkany(L, 1);
897  o = obj_at(L, 1);
898  if (!iscollectable(o))
899  lua_pushstring(L, "no collectable");
900  else {
901  static const char *gennames[] = {"new", "survival", "old0", "old1",
902  "old", "touched1", "touched2"};
903  GCObject *obj = gcvalue(o);
904  lua_pushstring(L, gennames[getage(obj)]);
905  }
906  return 1;
907 }
908 
909 
910 static int gc_printobj (lua_State *L) {
911  TValue *o;
912  luaL_checkany(L, 1);
913  o = obj_at(L, 1);
914  if (!iscollectable(o))
915  printf("no collectable\n");
916  else {
917  GCObject *obj = gcvalue(o);
918  printobj(G(L), obj);
919  printf("\n");
920  }
921  return 0;
922 }
923 
924 
925 static int gc_state (lua_State *L) {
926  static const char *statenames[] = {
927  "propagate", "atomic", "enteratomic", "sweepallgc", "sweepfinobj",
928  "sweeptobefnz", "sweepend", "callfin", "pause", ""};
929  static const int states[] = {
932  int option = states[luaL_checkoption(L, 1, "", statenames)];
933  if (option == -1) {
934  lua_pushstring(L, statenames[G(L)->gcstate]);
935  return 1;
936  }
937  else {
938  global_State *g = G(L);
939  if (G(L)->gckind == KGC_GEN)
940  luaL_error(L, "cannot change states in generational mode");
941  lua_lock(L);
942  if (option < g->gcstate) { /* must cross 'pause'? */
943  luaC_runtilstate(L, bitmask(GCSpause)); /* run until pause */
944  }
945  luaC_runtilstate(L, bitmask(option));
946  lua_assert(G(L)->gcstate == option);
947  lua_unlock(L);
948  return 0;
949  }
950 }
951 
952 
953 static int hash_query (lua_State *L) {
954  if (lua_isnone(L, 2)) {
955  luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected");
956  lua_pushinteger(L, tsvalue(obj_at(L, 1))->hash);
957  }
958  else {
959  TValue *o = obj_at(L, 1);
960  Table *t;
961  luaL_checktype(L, 2, LUA_TTABLE);
962  t = hvalue(obj_at(L, 2));
963  lua_pushinteger(L, luaH_mainposition(t, o) - t->node);
964  }
965  return 1;
966 }
967 
968 
969 static int stacklevel (lua_State *L) {
970  unsigned long a = 0;
971  lua_pushinteger(L, (L->top - L->stack));
972  lua_pushinteger(L, (L->stack_last - L->stack));
973  lua_pushinteger(L, L->nCcalls);
974  lua_pushinteger(L, L->nci);
975  lua_pushinteger(L, (unsigned long)&a);
976  return 5;
977 }
978 
979 
980 static int table_query (lua_State *L) {
981  const Table *t;
982  int i = cast_int(luaL_optinteger(L, 2, -1));
983  unsigned int asize;
984  luaL_checktype(L, 1, LUA_TTABLE);
985  t = hvalue(obj_at(L, 1));
986  asize = luaH_realasize(t);
987  if (i == -1) {
988  lua_pushinteger(L, asize);
990  lua_pushinteger(L, isdummy(t) ? 0 : t->lastfree - t->node);
991  lua_pushinteger(L, t->alimit);
992  return 4;
993  }
994  else if ((unsigned int)i < asize) {
995  lua_pushinteger(L, i);
996  pushobject(L, &t->array[i]);
997  lua_pushnil(L);
998  }
999  else if ((i -= asize) < sizenode(t)) {
1000  TValue k;
1001  getnodekey(L, &k, gnode(t, i));
1002  if (!isempty(gval(gnode(t, i))) ||
1003  ttisnil(&k) ||
1004  ttisnumber(&k)) {
1005  pushobject(L, &k);
1006  }
1007  else
1008  lua_pushliteral(L, "<undef>");
1009  pushobject(L, gval(gnode(t, i)));
1010  if (gnext(&t->node[i]) != 0)
1011  lua_pushinteger(L, gnext(&t->node[i]));
1012  else
1013  lua_pushnil(L);
1014  }
1015  return 3;
1016 }
1017 
1018 
1019 static int string_query (lua_State *L) {
1020  stringtable *tb = &G(L)->strt;
1021  int s = cast_int(luaL_optinteger(L, 1, 0)) - 1;
1022  if (s == -1) {
1023  lua_pushinteger(L ,tb->size);
1024  lua_pushinteger(L ,tb->nuse);
1025  return 2;
1026  }
1027  else if (s < tb->size) {
1028  TString *ts;
1029  int n = 0;
1030  for (ts = tb->hash[s]; ts != NULL; ts = ts->u.hnext) {
1031  setsvalue2s(L, L->top, ts);
1032  api_incr_top(L);
1033  n++;
1034  }
1035  return n;
1036  }
1037  else return 0;
1038 }
1039 
1040 
1041 static int tref (lua_State *L) {
1042  int level = lua_gettop(L);
1043  luaL_checkany(L, 1);
1044  lua_pushvalue(L, 1);
1046  lua_assert(lua_gettop(L) == level+1); /* +1 for result */
1047  return 1;
1048 }
1049 
1050 static int getref (lua_State *L) {
1051  int level = lua_gettop(L);
1053  lua_assert(lua_gettop(L) == level+1);
1054  return 1;
1055 }
1056 
1057 static int unref (lua_State *L) {
1058  int level = lua_gettop(L);
1060  lua_assert(lua_gettop(L) == level);
1061  return 0;
1062 }
1063 
1064 
1065 static int upvalue (lua_State *L) {
1066  int n = cast_int(luaL_checkinteger(L, 2));
1068  if (lua_isnone(L, 3)) {
1069  const char *name = lua_getupvalue(L, 1, n);
1070  if (name == NULL) return 0;
1071  lua_pushstring(L, name);
1072  return 2;
1073  }
1074  else {
1075  const char *name = lua_setupvalue(L, 1, n);
1076  lua_pushstring(L, name);
1077  return 1;
1078  }
1079 }
1080 
1081 
1082 static int newuserdata (lua_State *L) {
1083  size_t size = cast_sizet(luaL_optinteger(L, 1, 0));
1084  int nuv = luaL_optinteger(L, 2, 0);
1085  char *p = cast_charp(lua_newuserdatauv(L, size, nuv));
1086  while (size--) *p++ = '\0';
1087  return 1;
1088 }
1089 
1090 
1091 static int pushuserdata (lua_State *L) {
1092  lua_Integer u = luaL_checkinteger(L, 1);
1094  return 1;
1095 }
1096 
1097 
1098 static int udataval (lua_State *L) {
1099  lua_pushinteger(L, cast(long, lua_touserdata(L, 1)));
1100  return 1;
1101 }
1102 
1103 
1104 static int doonnewstack (lua_State *L) {
1105  lua_State *L1 = lua_newthread(L);
1106  size_t l;
1107  const char *s = luaL_checklstring(L, 1, &l);
1108  int status = luaL_loadbuffer(L1, s, l, s);
1109  if (status == LUA_OK)
1110  status = lua_pcall(L1, 0, 0, 0);
1111  lua_pushinteger(L, status);
1112  return 1;
1113 }
1114 
1115 
1116 static int s2d (lua_State *L) {
1117  lua_pushnumber(L, cast_num(*cast(const double *, luaL_checkstring(L, 1))));
1118  return 1;
1119 }
1120 
1121 
1122 static int d2s (lua_State *L) {
1123  double d = cast(double, luaL_checknumber(L, 1));
1124  lua_pushlstring(L, cast_charp(&d), sizeof(d));
1125  return 1;
1126 }
1127 
1128 
1129 static int num2int (lua_State *L) {
1130  lua_pushinteger(L, lua_tointeger(L, 1));
1131  return 1;
1132 }
1133 
1134 
1135 static int newstate (lua_State *L) {
1136  void *ud;
1137  lua_Alloc f = lua_getallocf(L, &ud);
1138  lua_State *L1 = lua_newstate(f, ud);
1139  if (L1) {
1140  lua_atpanic(L1, tpanic);
1141  lua_pushlightuserdata(L, L1);
1142  }
1143  else
1144  lua_pushnil(L);
1145  return 1;
1146 }
1147 
1148 
1149 static lua_State *getstate (lua_State *L) {
1150  lua_State *L1 = cast(lua_State *, lua_touserdata(L, 1));
1151  luaL_argcheck(L, L1 != NULL, 1, "state expected");
1152  return L1;
1153 }
1154 
1155 
1156 static int loadlib (lua_State *L) {
1157  static const luaL_Reg libs[] = {
1159  {"coroutine", luaopen_coroutine},
1160  {"debug", luaopen_debug},
1161  {"io", luaopen_io},
1162  {"os", luaopen_os},
1163  {"math", luaopen_math},
1164  {"string", luaopen_string},
1165  {"table", luaopen_table},
1166  {"T", luaB_opentests},
1167  {NULL, NULL}
1168  };
1169  lua_State *L1 = getstate(L);
1170  int i;
1171  luaL_requiref(L1, "package", luaopen_package, 0);
1172  lua_assert(lua_type(L1, -1) == LUA_TTABLE);
1173  /* 'requiref' should not reload module already loaded... */
1174  luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */
1175  /* ...but should return the same module */
1176  lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ));
1178  for (i = 0; libs[i].name; i++) {
1179  lua_pushcfunction(L1, libs[i].func);
1180  lua_setfield(L1, -2, libs[i].name);
1181  }
1182  return 0;
1183 }
1184 
1185 static int closestate (lua_State *L) {
1186  lua_State *L1 = getstate(L);
1187  lua_close(L1);
1188  return 0;
1189 }
1190 
1191 static int doremote (lua_State *L) {
1192  lua_State *L1 = getstate(L);
1193  size_t lcode;
1194  const char *code = luaL_checklstring(L, 2, &lcode);
1195  int status;
1196  lua_settop(L1, 0);
1197  status = luaL_loadbuffer(L1, code, lcode, code);
1198  if (status == LUA_OK)
1199  status = lua_pcall(L1, 0, LUA_MULTRET, 0);
1200  if (status != LUA_OK) {
1201  lua_pushnil(L);
1202  lua_pushstring(L, lua_tostring(L1, -1));
1203  lua_pushinteger(L, status);
1204  return 3;
1205  }
1206  else {
1207  int i = 0;
1208  while (!lua_isnone(L1, ++i))
1209  lua_pushstring(L, lua_tostring(L1, i));
1210  lua_pop(L1, i-1);
1211  return i-1;
1212  }
1213 }
1214 
1215 
1216 static int log2_aux (lua_State *L) {
1217  unsigned int x = (unsigned int)luaL_checkinteger(L, 1);
1219  return 1;
1220 }
1221 
1222 
1223 struct Aux { jmp_buf jb; const char *paniccode; lua_State *L; };
1224 
1225 /*
1226 ** does a long-jump back to "main program".
1227 */
1228 static int panicback (lua_State *L) {
1229  struct Aux *b;
1230  lua_checkstack(L, 1); /* open space for 'Aux' struct */
1231  lua_getfield(L, LUA_REGISTRYINDEX, "_jmpbuf"); /* get 'Aux' struct */
1232  b = (struct Aux *)lua_touserdata(L, -1);
1233  lua_pop(L, 1); /* remove 'Aux' struct */
1234  runC(b->L, L, b->paniccode); /* run optional panic code */
1235  longjmp(b->jb, 1);
1236  return 1; /* to avoid warnings */
1237 }
1238 
1239 static int checkpanic (lua_State *L) {
1240  struct Aux b;
1241  void *ud;
1242  lua_State *L1;
1243  const char *code = luaL_checkstring(L, 1);
1244  lua_Alloc f = lua_getallocf(L, &ud);
1245  b.paniccode = luaL_optstring(L, 2, "");
1246  b.L = L;
1247  L1 = lua_newstate(f, ud); /* create new state */
1248  if (L1 == NULL) { /* error? */
1249  lua_pushnil(L);
1250  return 1;
1251  }
1252  lua_atpanic(L1, panicback); /* set its panic function */
1253  lua_pushlightuserdata(L1, &b);
1254  lua_setfield(L1, LUA_REGISTRYINDEX, "_jmpbuf"); /* store 'Aux' struct */
1255  if (setjmp(b.jb) == 0) { /* set jump buffer */
1256  runC(L, L1, code); /* run code unprotected */
1257  lua_pushliteral(L, "no errors");
1258  }
1259  else { /* error handling */
1260  /* move error message to original state */
1261  lua_pushstring(L, lua_tostring(L1, -1));
1262  }
1263  lua_close(L1);
1264  return 1;
1265 }
1266 
1267 
1268 
1269 /*
1270 ** {====================================================================
1271 ** function to test the API with C. It interprets a kind of assembler
1272 ** language with calls to the API, so the test can be driven by Lua code
1273 ** =====================================================================
1274 */
1275 
1276 
1277 static void sethookaux (lua_State *L, int mask, int count, const char *code);
1278 
1279 static const char *const delimits = " \t\n,;";
1280 
1281 static void skip (const char **pc) {
1282  for (;;) {
1283  if (**pc != '\0' && strchr(delimits, **pc)) (*pc)++;
1284  else if (**pc == '#') { /* comment? */
1285  while (**pc != '\n' && **pc != '\0') (*pc)++; /* until end-of-line */
1286  }
1287  else break;
1288  }
1289 }
1290 
1291 static int getnum_aux (lua_State *L, lua_State *L1, const char **pc) {
1292  int res = 0;
1293  int sig = 1;
1294  skip(pc);
1295  if (**pc == '.') {
1296  res = cast_int(lua_tointeger(L1, -1));
1297  lua_pop(L1, 1);
1298  (*pc)++;
1299  return res;
1300  }
1301  else if (**pc == '*') {
1302  res = lua_gettop(L1);
1303  (*pc)++;
1304  return res;
1305  }
1306  else if (**pc == '-') {
1307  sig = -1;
1308  (*pc)++;
1309  }
1310  if (!lisdigit(cast_uchar(**pc)))
1311  luaL_error(L, "number expected (%s)", *pc);
1312  while (lisdigit(cast_uchar(**pc))) res = res*10 + (*(*pc)++) - '0';
1313  return sig*res;
1314 }
1315 
1316 static const char *getstring_aux (lua_State *L, char *buff, const char **pc) {
1317  int i = 0;
1318  skip(pc);
1319  if (**pc == '"' || **pc == '\'') { /* quoted string? */
1320  int quote = *(*pc)++;
1321  while (**pc != quote) {
1322  if (**pc == '\0') luaL_error(L, "unfinished string in C script");
1323  buff[i++] = *(*pc)++;
1324  }
1325  (*pc)++;
1326  }
1327  else {
1328  while (**pc != '\0' && !strchr(delimits, **pc))
1329  buff[i++] = *(*pc)++;
1330  }
1331  buff[i] = '\0';
1332  return buff;
1333 }
1334 
1335 
1336 static int getindex_aux (lua_State *L, lua_State *L1, const char **pc) {
1337  skip(pc);
1338  switch (*(*pc)++) {
1339  case 'R': return LUA_REGISTRYINDEX;
1340  case 'G': return luaL_error(L, "deprecated index 'G'");
1341  case 'U': return lua_upvalueindex(getnum_aux(L, L1, pc));
1342  default: (*pc)--; return getnum_aux(L, L1, pc);
1343  }
1344 }
1345 
1346 
1347 static const char *const statcodes[] = {"OK", "YIELD", "ERRRUN",
1348  "ERRSYNTAX", MEMERRMSG, "ERRGCMM", "ERRERR"};
1349 
1350 /*
1351 ** Avoid these stat codes from being collected, to avoid possible
1352 ** memory error when pushing them.
1353 */
1354 static void regcodes (lua_State *L) {
1355  unsigned int i;
1356  for (i = 0; i < sizeof(statcodes) / sizeof(statcodes[0]); i++) {
1357  lua_pushboolean(L, 1);
1358  lua_setfield(L, LUA_REGISTRYINDEX, statcodes[i]);
1359  }
1360 }
1361 
1362 
1363 #define EQ(s1) (strcmp(s1, inst) == 0)
1364 
1365 #define getnum (getnum_aux(L, L1, &pc))
1366 #define getstring (getstring_aux(L, buff, &pc))
1367 #define getindex (getindex_aux(L, L1, &pc))
1368 
1369 
1370 static int testC (lua_State *L);
1371 static int Cfunck (lua_State *L, int status, lua_KContext ctx);
1372 
1373 /*
1374 ** arithmetic operation encoding for 'arith' instruction
1375 ** LUA_OPIDIV -> \
1376 ** LUA_OPSHL -> <
1377 ** LUA_OPSHR -> >
1378 ** LUA_OPUNM -> _
1379 ** LUA_OPBNOT -> !
1380 */
1381 static const char ops[] = "+-*%^/\\&|~<>_!";
1382 
1383 static int runC (lua_State *L, lua_State *L1, const char *pc) {
1384  char buff[300];
1385  int status = 0;
1386  if (pc == NULL) return luaL_error(L, "attempt to runC null script");
1387  for (;;) {
1388  const char *inst = getstring;
1389  if EQ("") return 0;
1390  else if EQ("absindex") {
1391  lua_pushnumber(L1, lua_absindex(L1, getindex));
1392  }
1393  else if EQ("append") {
1394  int t = getindex;
1395  int i = lua_rawlen(L1, t);
1396  lua_rawseti(L1, t, i + 1);
1397  }
1398  else if EQ("arith") {
1399  int op;
1400  skip(&pc);
1401  op = strchr(ops, *pc++) - ops;
1402  lua_arith(L1, op);
1403  }
1404  else if EQ("call") {
1405  int narg = getnum;
1406  int nres = getnum;
1407  lua_call(L1, narg, nres);
1408  }
1409  else if EQ("callk") {
1410  int narg = getnum;
1411  int nres = getnum;
1412  int i = getindex;
1413  lua_callk(L1, narg, nres, i, Cfunck);
1414  }
1415  else if EQ("checkstack") {
1416  int sz = getnum;
1417  const char *msg = getstring;
1418  if (*msg == '\0')
1419  msg = NULL; /* to test 'luaL_checkstack' with no message */
1420  luaL_checkstack(L1, sz, msg);
1421  }
1422  else if EQ("rawcheckstack") {
1423  int sz = getnum;
1424  lua_pushboolean(L1, lua_checkstack(L1, sz));
1425  }
1426  else if EQ("compare") {
1427  const char *opt = getstring; /* EQ, LT, or LE */
1428  int op = (opt[0] == 'E') ? LUA_OPEQ
1429  : (opt[1] == 'T') ? LUA_OPLT : LUA_OPLE;
1430  int a = getindex;
1431  int b = getindex;
1432  lua_pushboolean(L1, lua_compare(L1, a, b, op));
1433  }
1434  else if EQ("concat") {
1435  lua_concat(L1, getnum);
1436  }
1437  else if EQ("copy") {
1438  int f = getindex;
1439  lua_copy(L1, f, getindex);
1440  }
1441  else if EQ("func2num") {
1442  lua_CFunction func = lua_tocfunction(L1, getindex);
1443  lua_pushnumber(L1, cast_sizet(func));
1444  }
1445  else if EQ("getfield") {
1446  int t = getindex;
1447  lua_getfield(L1, t, getstring);
1448  }
1449  else if EQ("getglobal") {
1450  lua_getglobal(L1, getstring);
1451  }
1452  else if EQ("getmetatable") {
1453  if (lua_getmetatable(L1, getindex) == 0)
1454  lua_pushnil(L1);
1455  }
1456  else if EQ("gettable") {
1457  lua_gettable(L1, getindex);
1458  }
1459  else if EQ("gettop") {
1460  lua_pushinteger(L1, lua_gettop(L1));
1461  }
1462  else if EQ("gsub") {
1463  int a = getnum; int b = getnum; int c = getnum;
1464  luaL_gsub(L1, lua_tostring(L1, a),
1465  lua_tostring(L1, b),
1466  lua_tostring(L1, c));
1467  }
1468  else if EQ("insert") {
1469  lua_insert(L1, getnum);
1470  }
1471  else if EQ("iscfunction") {
1472  lua_pushboolean(L1, lua_iscfunction(L1, getindex));
1473  }
1474  else if EQ("isfunction") {
1475  lua_pushboolean(L1, lua_isfunction(L1, getindex));
1476  }
1477  else if EQ("isnil") {
1478  lua_pushboolean(L1, lua_isnil(L1, getindex));
1479  }
1480  else if EQ("isnull") {
1481  lua_pushboolean(L1, lua_isnone(L1, getindex));
1482  }
1483  else if EQ("isnumber") {
1484  lua_pushboolean(L1, lua_isnumber(L1, getindex));
1485  }
1486  else if EQ("isstring") {
1487  lua_pushboolean(L1, lua_isstring(L1, getindex));
1488  }
1489  else if EQ("istable") {
1490  lua_pushboolean(L1, lua_istable(L1, getindex));
1491  }
1492  else if EQ("isudataval") {
1493  lua_pushboolean(L1, lua_islightuserdata(L1, getindex));
1494  }
1495  else if EQ("isuserdata") {
1496  lua_pushboolean(L1, lua_isuserdata(L1, getindex));
1497  }
1498  else if EQ("len") {
1499  lua_len(L1, getindex);
1500  }
1501  else if EQ("Llen") {
1502  lua_pushinteger(L1, luaL_len(L1, getindex));
1503  }
1504  else if EQ("loadfile") {
1506  }
1507  else if EQ("loadstring") {
1508  const char *s = luaL_checkstring(L1, getnum);
1509  luaL_loadstring(L1, s);
1510  }
1511  else if EQ("newmetatable") {
1512  lua_pushboolean(L1, luaL_newmetatable(L1, getstring));
1513  }
1514  else if EQ("newtable") {
1515  lua_newtable(L1);
1516  }
1517  else if EQ("newthread") {
1518  lua_newthread(L1);
1519  }
1520  else if EQ("resetthread") {
1522  }
1523  else if EQ("newuserdata") {
1524  lua_newuserdata(L1, getnum);
1525  }
1526  else if EQ("next") {
1527  lua_next(L1, -2);
1528  }
1529  else if EQ("objsize") {
1530  lua_pushinteger(L1, lua_rawlen(L1, getindex));
1531  }
1532  else if EQ("pcall") {
1533  int narg = getnum;
1534  int nres = getnum;
1535  status = lua_pcall(L1, narg, nres, getnum);
1536  }
1537  else if EQ("pcallk") {
1538  int narg = getnum;
1539  int nres = getnum;
1540  int i = getindex;
1541  status = lua_pcallk(L1, narg, nres, 0, i, Cfunck);
1542  }
1543  else if EQ("pop") {
1544  lua_pop(L1, getnum);
1545  }
1546  else if EQ("printstack") {
1547  int n = getnum;
1548  if (n != 0) {
1549  printf("%s\n", luaL_tolstring(L1, n, NULL));
1550  lua_pop(L1, 1);
1551  }
1552  else printstack(L1);
1553  }
1554  else if EQ("print") {
1555  const char *msg = getstring;
1556  printf("%s\n", msg);
1557  }
1558  else if EQ("warningC") {
1559  const char *msg = getstring;
1560  lua_warning(L1, msg, 1);
1561  }
1562  else if EQ("warning") {
1563  const char *msg = getstring;
1564  lua_warning(L1, msg, 0);
1565  }
1566  else if EQ("pushbool") {
1567  lua_pushboolean(L1, getnum);
1568  }
1569  else if EQ("pushcclosure") {
1570  lua_pushcclosure(L1, testC, getnum);
1571  }
1572  else if EQ("pushint") {
1573  lua_pushinteger(L1, getnum);
1574  }
1575  else if EQ("pushnil") {
1576  lua_pushnil(L1);
1577  }
1578  else if EQ("pushnum") {
1580  }
1581  else if EQ("pushstatus") {
1582  lua_pushstring(L1, statcodes[status]);
1583  }
1584  else if EQ("pushstring") {
1585  lua_pushstring(L1, getstring);
1586  }
1587  else if EQ("pushupvalueindex") {
1589  }
1590  else if EQ("pushvalue") {
1591  lua_pushvalue(L1, getindex);
1592  }
1593  else if EQ("pushfstringI") {
1594  lua_pushfstring(L1, lua_tostring(L, -2), (int)lua_tointeger(L, -1));
1595  }
1596  else if EQ("pushfstringS") {
1597  lua_pushfstring(L1, lua_tostring(L, -2), lua_tostring(L, -1));
1598  }
1599  else if EQ("pushfstringP") {
1600  lua_pushfstring(L1, lua_tostring(L, -2), lua_topointer(L, -1));
1601  }
1602  else if EQ("rawget") {
1603  int t = getindex;
1604  lua_rawget(L1, t);
1605  }
1606  else if EQ("rawgeti") {
1607  int t = getindex;
1608  lua_rawgeti(L1, t, getnum);
1609  }
1610  else if EQ("rawgetp") {
1611  int t = getindex;
1613  }
1614  else if EQ("rawset") {
1615  int t = getindex;
1616  lua_rawset(L1, t);
1617  }
1618  else if EQ("rawseti") {
1619  int t = getindex;
1620  lua_rawseti(L1, t, getnum);
1621  }
1622  else if EQ("rawsetp") {
1623  int t = getindex;
1625  }
1626  else if EQ("remove") {
1627  lua_remove(L1, getnum);
1628  }
1629  else if EQ("replace") {
1630  lua_replace(L1, getindex);
1631  }
1632  else if EQ("resume") {
1633  int i = getindex;
1634  int nres;
1635  status = lua_resume(lua_tothread(L1, i), L, getnum, &nres);
1636  }
1637  else if EQ("return") {
1638  int n = getnum;
1639  if (L1 != L) {
1640  int i;
1641  for (i = 0; i < n; i++) {
1642  int idx = -(n - i);
1643  switch (lua_type(L1, idx)) {
1644  case LUA_TBOOLEAN:
1645  lua_pushboolean(L, lua_toboolean(L1, idx));
1646  break;
1647  default:
1648  lua_pushstring(L, lua_tostring(L1, idx));
1649  break;
1650  }
1651  }
1652  }
1653  return n;
1654  }
1655  else if EQ("rotate") {
1656  int i = getindex;
1657  lua_rotate(L1, i, getnum);
1658  }
1659  else if EQ("setfield") {
1660  int t = getindex;
1661  const char *s = getstring;
1662  lua_setfield(L1, t, s);
1663  }
1664  else if EQ("seti") {
1665  int t = getindex;
1666  lua_seti(L1, t, getnum);
1667  }
1668  else if EQ("setglobal") {
1669  const char *s = getstring;
1670  lua_setglobal(L1, s);
1671  }
1672  else if EQ("sethook") {
1673  int mask = getnum;
1674  int count = getnum;
1675  const char *s = getstring;
1676  sethookaux(L1, mask, count, s);
1677  }
1678  else if EQ("setmetatable") {
1679  int idx = getindex;
1680  lua_setmetatable(L1, idx);
1681  }
1682  else if EQ("settable") {
1683  lua_settable(L1, getindex);
1684  }
1685  else if EQ("settop") {
1686  lua_settop(L1, getnum);
1687  }
1688  else if EQ("testudata") {
1689  int i = getindex;
1690  lua_pushboolean(L1, luaL_testudata(L1, i, getstring) != NULL);
1691  }
1692  else if EQ("error") {
1693  lua_error(L1);
1694  }
1695  else if EQ("abort") {
1696  abort();
1697  }
1698  else if EQ("throw") {
1699 #if defined(__cplusplus)
1700 static struct X { int x; } x;
1701  throw x;
1702 #else
1703  luaL_error(L1, "C++");
1704 #endif
1705  break;
1706  }
1707  else if EQ("tobool") {
1708  lua_pushboolean(L1, lua_toboolean(L1, getindex));
1709  }
1710  else if EQ("tocfunction") {
1711  lua_pushcfunction(L1, lua_tocfunction(L1, getindex));
1712  }
1713  else if EQ("tointeger") {
1714  lua_pushinteger(L1, lua_tointeger(L1, getindex));
1715  }
1716  else if EQ("tonumber") {
1717  lua_pushnumber(L1, lua_tonumber(L1, getindex));
1718  }
1719  else if EQ("topointer") {
1720  lua_pushlightuserdata(L1, cast_voidp(lua_topointer(L1, getindex)));
1721  }
1722  else if EQ("touserdata") {
1723  lua_pushlightuserdata(L1, lua_touserdata(L1, getindex));
1724  }
1725  else if EQ("tostring") {
1726  const char *s = lua_tostring(L1, getindex);
1727  const char *s1 = lua_pushstring(L1, s);
1728  lua_longassert((s == NULL && s1 == NULL) || strcmp(s, s1) == 0);
1729  }
1730  else if EQ("type") {
1732  }
1733  else if EQ("xmove") {
1734  int f = getindex;
1735  int t = getindex;
1736  lua_State *fs = (f == 0) ? L1 : lua_tothread(L1, f);
1737  lua_State *ts = (t == 0) ? L1 : lua_tothread(L1, t);
1738  int n = getnum;
1739  if (n == 0) n = lua_gettop(fs);
1740  lua_xmove(fs, ts, n);
1741  }
1742  else if EQ("isyieldable") {
1743  lua_pushboolean(L1, lua_isyieldable(lua_tothread(L1, getindex)));
1744  }
1745  else if EQ("yield") {
1746  return lua_yield(L1, getnum);
1747  }
1748  else if EQ("yieldk") {
1749  int nres = getnum;
1750  int i = getindex;
1751  return lua_yieldk(L1, nres, i, Cfunck);
1752  }
1753  else if EQ("toclose") {
1754  lua_toclose(L1, getnum);
1755  }
1756  else luaL_error(L, "unknown instruction %s", buff);
1757  }
1758  return 0;
1759 }
1760 
1761 
1762 static int testC (lua_State *L) {
1763  lua_State *L1;
1764  const char *pc;
1765  if (lua_isuserdata(L, 1)) {
1766  L1 = getstate(L);
1767  pc = luaL_checkstring(L, 2);
1768  }
1769  else if (lua_isthread(L, 1)) {
1770  L1 = lua_tothread(L, 1);
1771  pc = luaL_checkstring(L, 2);
1772  }
1773  else {
1774  L1 = L;
1775  pc = luaL_checkstring(L, 1);
1776  }
1777  return runC(L, L1, pc);
1778 }
1779 
1780 
1781 static int Cfunc (lua_State *L) {
1782  return runC(L, L, lua_tostring(L, lua_upvalueindex(1)));
1783 }
1784 
1785 
1786 static int Cfunck (lua_State *L, int status, lua_KContext ctx) {
1787  lua_pushstring(L, statcodes[status]);
1788  lua_setglobal(L, "status");
1789  lua_pushinteger(L, ctx);
1790  lua_setglobal(L, "ctx");
1791  return runC(L, L, lua_tostring(L, ctx));
1792 }
1793 
1794 
1795 static int makeCfunc (lua_State *L) {
1796  luaL_checkstring(L, 1);
1797  lua_pushcclosure(L, Cfunc, lua_gettop(L));
1798  return 1;
1799 }
1800 
1801 
1802 /* }====================================================== */
1803 
1804 
1805 /*
1806 ** {======================================================
1807 ** tests for C hooks
1808 ** =======================================================
1809 */
1810 
1811 /*
1812 ** C hook that runs the C script stored in registry.C_HOOK[L]
1813 */
1814 static void Chook (lua_State *L, lua_Debug *ar) {
1815  const char *scpt;
1816  const char *const events [] = {"call", "ret", "line", "count", "tailcall"};
1817  lua_getfield(L, LUA_REGISTRYINDEX, "C_HOOK");
1818  lua_pushlightuserdata(L, L);
1819  lua_gettable(L, -2); /* get C_HOOK[L] (script saved by sethookaux) */
1820  scpt = lua_tostring(L, -1); /* not very religious (string will be popped) */
1821  lua_pop(L, 2); /* remove C_HOOK and script */
1822  lua_pushstring(L, events[ar->event]); /* may be used by script */
1823  lua_pushinteger(L, ar->currentline); /* may be used by script */
1824  runC(L, L, scpt); /* run script from C_HOOK[L] */
1825 }
1826 
1827 
1828 /*
1829 ** sets 'registry.C_HOOK[L] = scpt' and sets 'Chook' as a hook
1830 */
1831 static void sethookaux (lua_State *L, int mask, int count, const char *scpt) {
1832  if (*scpt == '\0') { /* no script? */
1833  lua_sethook(L, NULL, 0, 0); /* turn off hooks */
1834  return;
1835  }
1836  lua_getfield(L, LUA_REGISTRYINDEX, "C_HOOK"); /* get C_HOOK table */
1837  if (!lua_istable(L, -1)) { /* no hook table? */
1838  lua_pop(L, 1); /* remove previous value */
1839  lua_newtable(L); /* create new C_HOOK table */
1840  lua_pushvalue(L, -1);
1841  lua_setfield(L, LUA_REGISTRYINDEX, "C_HOOK"); /* register it */
1842  }
1843  lua_pushlightuserdata(L, L);
1844  lua_pushstring(L, scpt);
1845  lua_settable(L, -3); /* C_HOOK[L] = script */
1846  lua_sethook(L, Chook, mask, count);
1847 }
1848 
1849 
1850 static int sethook (lua_State *L) {
1851  if (lua_isnoneornil(L, 1))
1852  lua_sethook(L, NULL, 0, 0); /* turn off hooks */
1853  else {
1854  const char *scpt = luaL_checkstring(L, 1);
1855  const char *smask = luaL_checkstring(L, 2);
1856  int count = cast_int(luaL_optinteger(L, 3, 0));
1857  int mask = 0;
1858  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
1859  if (strchr(smask, 'r')) mask |= LUA_MASKRET;
1860  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
1861  if (count > 0) mask |= LUA_MASKCOUNT;
1862  sethookaux(L, mask, count, scpt);
1863  }
1864  return 0;
1865 }
1866 
1867 
1868 static int coresume (lua_State *L) {
1869  int status, nres;
1870  lua_State *co = lua_tothread(L, 1);
1871  luaL_argcheck(L, co, 1, "coroutine expected");
1872  status = lua_resume(co, L, 0, &nres);
1873  if (status != LUA_OK && status != LUA_YIELD) {
1874  lua_pushboolean(L, 0);
1875  lua_insert(L, -2);
1876  return 2; /* return false + error message */
1877  }
1878  else {
1879  lua_pushboolean(L, 1);
1880  return 1;
1881  }
1882 }
1883 
1884 /* }====================================================== */
1885 
1886 
1887 
1888 static const struct luaL_Reg tests_funcs[] = {
1889  {"checkmemory", lua_checkmemory},
1890  {"closestate", closestate},
1891  {"d2s", d2s},
1892  {"doonnewstack", doonnewstack},
1893  {"doremote", doremote},
1894  {"gccolor", gc_color},
1895  {"gcage", gc_age},
1896  {"gcstate", gc_state},
1897  {"pobj", gc_printobj},
1898  {"getref", getref},
1899  {"hash", hash_query},
1900  {"log2", log2_aux},
1901  {"limits", get_limits},
1902  {"listcode", listcode},
1903  {"printcode", printcode},
1904  {"listk", listk},
1905  {"listabslineinfo", listabslineinfo},
1906  {"listlocals", listlocals},
1907  {"loadlib", loadlib},
1908  {"checkpanic", checkpanic},
1909  {"newstate", newstate},
1910  {"newuserdata", newuserdata},
1911  {"num2int", num2int},
1912  {"pushuserdata", pushuserdata},
1913  {"querystr", string_query},
1914  {"querytab", table_query},
1915  {"ref", tref},
1916  {"resume", coresume},
1917  {"s2d", s2d},
1918  {"sethook", sethook},
1919  {"stacklevel", stacklevel},
1920  {"testC", testC},
1921  {"makeCfunc", makeCfunc},
1922  {"totalmem", mem_query},
1923  {"alloccount", alloc_count},
1924  {"allocfailnext", alloc_failnext},
1925  {"trick", settrick},
1926  {"udataval", udataval},
1927  {"unref", unref},
1928  {"upvalue", upvalue},
1929  {NULL, NULL}
1930 };
1931 
1932 
1933 static void checkfinalmem (void) {
1934  lua_assert(l_memcontrol.numblocks == 0);
1935  lua_assert(l_memcontrol.total == 0);
1936 }
1937 
1938 
1939 int luaB_opentests (lua_State *L) {
1940  void *ud;
1941  lua_atpanic(L, &tpanic);
1942  lua_setwarnf(L, &warnf, L);
1943  lua_pushboolean(L, 0);
1944  lua_setglobal(L, "_WARN"); /* _WARN = false */
1945  regcodes(L);
1946  atexit(checkfinalmem);
1948  lua_assert(ud == cast_voidp(&l_memcontrol));
1949  lua_setallocf(L, lua_getallocf(L, NULL), ud);
1950  luaL_newlib(L, tests_funcs);
1951  return 1;
1952 }
1953 
1954 #endif
1955 
LUA_API int lua_isstring(lua_State *L, int idx)
Definition: lapi.c:292
LUA_API const char * lua_getupvalue(lua_State *L, int funcindex, int n)
Definition: lapi.c:1352
#define getage(o)
Definition: lgc.h:116
#define lua_isnoneornil(L, n)
Definition: lua.h:379
Definition: lua.h:469
LUA_API void lua_xmove(lua_State *from, lua_State *to, int n)
Definition: lapi.c:120
#define tofinalize(x)
Definition: lgc.h:92
TString * source
Definition: lobject.h:549
LUALIB_API int luaL_ref(lua_State *L, int t)
Definition: lauxlib.c:646
#define lua_pushcfunction(L, f)
Definition: lua.h:370
#define GCSswptobefnz
Definition: lgc.h:36
#define TESTBIT
Definition: lgc.h:80
LUA_API void lua_toclose(lua_State *L, int idx)
Definition: lapi.c:1237
LUA_API int lua_rawget(lua_State *L, int idx)
Definition: lapi.c:698
void * l_Trick
#define cast_num(i)
Definition: llimits.h:127
#define LUA_VTHREAD
Definition: lobject.h:238
#define gcvalue(o)
Definition: lobject.h:281
int lua_resetthread(lua_State *L)
Definition: lstate.c:363
#define s2v(o)
Definition: lobject.h:148
Definition: lobject.h:712
LUALIB_API int luaL_checkoption(lua_State *L, int arg, const char *def, const char *const lst[])
Definition: lauxlib.c:360
#define GCSswpfinobj
Definition: lgc.h:35
#define MAXARG_Ax
Definition: lopcodes.h:83
LUA_API int lua_yieldk(lua_State *L, int nresults, lua_KContext ctx, lua_KFunction k)
Definition: ldo.c:706
#define lua_isnone(L, n)
Definition: lua.h:378
#define obj2gco(v)
Definition: lstate.h:381
LUA_API void lua_pushnil(lua_State *L)
Definition: lapi.c:473
LUA_API int lua_isnumber(lua_State *L, int idx)
Definition: lapi.c:285
#define LUA_VCCL
Definition: lobject.h:568
LUA_KCONTEXT lua_KContext
Definition: lua.h:100
LUA_API const void * lua_topointer(lua_State *L, int idx)
Definition: lapi.c:451
#define gnode(t, i)
Definition: ltable.h:13
LUA_API int lua_rawgeti(lua_State *L, int idx, lua_Integer n)
Definition: lapi.c:710
#define GETARG_sBx(i)
Definition: lopcodes.h:146
unsigned long memlimit
Definition: ltests.h:58
StkId stack
Definition: lstate.h:315
Definition: lobject.h:528
void lua_setwarnf(lua_State *L, lua_WarnFunction f, void *ud)
Definition: lapi.c:1295
unsigned short nuvalue
Definition: lobject.h:439
#define gco2t(o)
Definition: lstate.h:371
#define LUA_MULTRET
Definition: lua.h:36
#define gval(n)
Definition: ltable.h:14
#define ttisstring(o)
Definition: lobject.h:339
#define gco2lcl(o)
Definition: lstate.h:367
LUA_API int lua_isyieldable(lua_State *L)
Definition: ldo.c:701
LUA_API int lua_resume(lua_State *L, lua_State *from, int nargs, int *nresults)
Definition: ldo.c:661
LUA_API int lua_setmetatable(lua_State *L, int objindex)
Definition: lapi.c:901
LUAMOD_API int luaopen_debug(lua_State *L)
Definition: ldblib.c:473
unsigned long total
Definition: ltests.h:56
#define LUA_MASKRET
Definition: lua.h:440
LUA_API int lua_toboolean(lua_State *L, int idx)
Definition: lapi.c:375
#define LUA_MASKCOUNT
Definition: lua.h:442
LUA_API void lua_rawsetp(lua_State *L, int idx, const void *p)
Definition: lapi.c:882
#define GCSpause
Definition: lgc.h:39
#define iswhite(x)
Definition: lgc.h:87
#define LUA_GNAME
Definition: lauxlib.h:19
LUAMOD_API int luaopen_os(lua_State *L)
Definition: loslib.c:426
MQTTClient d
Definition: test10.c:1656
LUA_API void lua_setallocf(lua_State *L, lua_Alloc f, void *ud)
Definition: lapi.c:1287
LUA_API void lua_rawset(lua_State *L, int idx)
Definition: lapi.c:877
#define LUA_MASKCALL
Definition: lua.h:439
#define getproto(o)
Definition: lobject.h:642
const char * name
Definition: lauxlib.h:38
LUA_API void * lua_touserdata(lua_State *L, int idx)
Definition: lapi.c:432
int sizep
Definition: lobject.h:537
static int getnum(const char **fmt, int df)
Definition: lstrlib.c:1404
#define cast_voidp(i)
Definition: llimits.h:126
LUA_API void lua_seti(lua_State *L, int idx, lua_Integer n)
Definition: lapi.c:843
static void warnf(void *ud, const char *message, int tocont)
Definition: lauxlib.c:1014
unsigned short nci
Definition: lstate.h:310
LUALIB_API int luaL_loadstring(lua_State *L, const char *s)
Definition: lauxlib.c:815
#define UNUSED(x)
Definition: llimits.h:118
#define NUM_OPCODES
Definition: lopcodes.h:312
#define LUAI_MAXALIGN
Definition: luaconf.h:756
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
Definition: lapi.c:837
#define LUA_PRELOAD_TABLE
Definition: lauxlib.h:34
#define lua_remove(L, idx)
Definition: lua.h:391
#define gco2th(o)
Definition: lstate.h:373
lua_State * L
Definition: lstrlib.c:1376
LUA_API int lua_compare(lua_State *L, int index1, int index2, int op)
Definition: lapi.c:327
StkId top
Definition: lstate.h:195
int failnext
Definition: ltests.h:54
Definition: lobject.h:63
LUALIB_API const char * luaL_gsub(lua_State *L, const char *s, const char *p, const char *r)
Definition: lauxlib.c:978
GCObject * finobj
Definition: lstate.h:274
#define cast(t, exp)
Definition: llimits.h:123
#define lua_tointeger(L, i)
Definition: lua.h:362
LUA_API lua_State * lua_newstate(lua_Alloc f, void *ud)
Definition: lstate.c:385
int event
Definition: lua.h:470
LUAMOD_API int luaopen_package(lua_State *L)
Definition: loadlib.c:736
#define LUA_VTABLE
Definition: lobject.h:653
void luaC_runtilstate(lua_State *L, int statesmask)
Definition: lgc.c:1625
#define malloc(x)
Definition: Heap.h:41
LUA_API int lua_error(lua_State *L)
Definition: lapi.c:1205
Definition: lopcodes.h:32
#define G(L)
Definition: lstate.h:332
GCObject * tobefnz
Definition: lstate.h:280
#define lua_tonumber(L, i)
Definition: lua.h:361
#define luaL_typename(L, i)
Definition: lauxlib.h:141
LUAMOD_API int luaopen_coroutine(lua_State *L)
Definition: lcorolib.c:203
#define lua_unlock(L)
Definition: llimits.h:243
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
Definition: lauxlib.c:311
#define LUA_TFUNCTION
Definition: lua.h:71
#define upisopen(up)
Definition: lfunc.h:32
LUAI_FUNC int lua_checkmemory(lua_State *L)
#define GCSswpend
Definition: lgc.h:37
LocVar * locvars
Definition: lobject.h:548
#define GET_OPCODE(i)
Definition: lopcodes.h:114
Definition: lopcodes.h:32
#define getnodekey(L, obj, node)
Definition: lobject.h:693
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
Definition: lapi.c:514
AbsLineInfo * abslineinfo
Definition: lobject.h:547
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition: json.hpp:4680
#define GCSatomic
Definition: lgc.h:33
LUA_API int lua_isuserdata(lua_State *L, int idx)
Definition: lapi.c:298
#define gnext(n)
Definition: ltable.h:15
#define keepinvariant(g)
Definition: lgc.h:54
const char * luaF_getlocalname(const Proto *f, int local_number, int pc)
Definition: lfunc.c:289
LUAMOD_API int luaopen_io(lua_State *L)
Definition: liolib.c:812
UpVal * upvals[1]
Definition: lobject.h:632
LUA_API void lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
Definition: ldebug.c:135
GCObject * allgc
Definition: lstate.h:272
LUAI_FUNC void lua_printobj(lua_State *L, struct GCObject *o)
unsigned long countlimit
Definition: ltests.h:59
LUA_API void * debug_realloc(void *ud, void *block, size_t osize, size_t nsize)
int sizelocvars
Definition: lobject.h:538
static int stacklevel(FuncState *fs, int nvar)
Definition: lparser.c:230
ls_byte * lineinfo
Definition: lobject.h:546
#define free(x)
Definition: Heap.h:55
#define lua_pop(L, n)
Definition: lua.h:364
unsigned int type
Definition: MQTTPacket.h:80
#define KGC_GEN
Definition: lstate.h:180
#define luaL_loadbuffer(L, s, sz, n)
Definition: lauxlib.h:153
LUA_API void lua_pushvalue(lua_State *L, int idx)
Definition: lapi.c:246
OpCode
Definition: lopcodes.h:196
Upvaldesc * upvalues
Definition: lobject.h:545
LUA_API int lua_rawgetp(lua_State *L, int idx, const void *p)
Definition: lapi.c:718
#define luaL_loadfile(L, f)
Definition: lauxlib.h:94
#define LUA_OPLT
Definition: lua.h:223
#define isempty(v)
Definition: lobject.h:193
unsigned long lu_mem
Definition: llimits.h:30
struct Table * metatable
Definition: lobject.h:441
StkId top
Definition: lstate.h:311
LUA_API void lua_settop(lua_State *L, int idx)
Definition: lapi.c:173
LUA_API int lua_getmetatable(lua_State *L, int objindex)
Definition: lapi.c:741
lu_byte gckind
Definition: lstate.h:264
Definition: lopcodes.h:32
#define righttt(obj)
Definition: lobject.h:94
Definition: lopcodes.h:32
StkId stack_last
Definition: lstate.h:314
#define lua_lock(L)
Definition: llimits.h:242
#define lua_isthread(L, n)
Definition: lua.h:377
LUA_API void lua_setglobal(lua_State *L, const char *name)
Definition: lapi.c:813
LUA_API int lua_getglobal(lua_State *L, const char *name)
Definition: lapi.c:632
#define lua_upvalueindex(i)
Definition: lua.h:45
LUAMOD_API int luaopen_table(lua_State *L)
Definition: ltablib.c:424
#define lua_pcall(L, n, r, f)
Definition: lua.h:287
LUA_INTEGER lua_Integer
Definition: lua.h:94
#define LUA_TSTRING
Definition: lua.h:69
int luaO_ceillog2(unsigned int x)
Definition: lobject.c:35
#define getstr(ts)
Definition: lobject.h:379
#define gco2u(o)
Definition: lstate.h:366
#define lisdigit(c)
Definition: lctype.h:91
int nuse
Definition: lstate.h:185
constexpr size_t count()
Definition: core.h:960
Definition: lobject.h:604
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.c:330
LUAMOD_API int luaopen_base(lua_State *L)
Definition: lbaselib.c:515
#define testbit(x, b)
Definition: lgc.h:67
#define GETARG_C(i)
Definition: lopcodes.h:132
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:106
struct lua_State * mainthread
Definition: lstate.h:292
TValue * v
Definition: lobject.h:607
LUALIB_API const char * luaL_checklstring(lua_State *L, int arg, size_t *len)
Definition: lauxlib.c:402
LUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf)
Definition: lapi.c:136
#define lua_newuserdata(L, s)
Definition: lua.h:411
LUA_API void lua_settable(lua_State *L, int idx)
Definition: lapi.c:821
#define LUA_YIELD
Definition: lua.h:50
#define GETARG_A(i)
Definition: lopcodes.h:125
TValue uv
Definition: lobject.h:428
void *(* lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize)
Definition: lua.h:125
#define LUA_VSHRSTR
Definition: lobject.h:336
CallInfo * ci
Definition: lstate.h:313
#define allocsizenode(t)
Definition: ltable.h:31
#define ttisnil(v)
Definition: lobject.h:169
LUA_API void lua_pushboolean(lua_State *L, int b)
Definition: lapi.c:581
LUA_API int lua_iscfunction(lua_State *L, int idx)
Definition: lapi.c:273
lu_byte currentwhite
Definition: lstate.h:262
GCObject * finobjold1
Definition: lstate.h:288
UValue uv[1]
Definition: lobject.h:443
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
Definition: lapi.c:889
#define api_incr_top(L)
Definition: lapi.h:16
#define GCScallfin
Definition: lgc.h:38
#define clLvalue(o)
Definition: lobject.h:579
#define LFIELDS_PER_FLUSH
Definition: lopcodes.h:390
#define GETARG_k(i)
Definition: lopcodes.h:137
l_uint32 nCcalls
Definition: lstate.h:323
#define l_setbit(x, b)
Definition: lgc.h:65
#define LUA_VLNGSTR
Definition: lobject.h:337
LUA_API void lua_close(lua_State *L)
Definition: lstate.c:441
StkId func
Definition: lstate.h:194
#define isdead(g, v)
Definition: lgc.h:96
static void block(LexState *ls)
Definition: lparser.c:1295
#define gco2p(o)
Definition: lstate.h:372
LUA_API int lua_pcallk(lua_State *L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k)
Definition: lapi.c:1010
union UpVal::@22 u
TString * varname
Definition: lobject.h:504
int sizeabslineinfo
Definition: lobject.h:539
TValue * array
Definition: lobject.h:717
#define cast_charp(i)
Definition: llimits.h:133
#define gco2ccl(o)
Definition: lstate.h:368
LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)
Definition: lapi.c:414
LUA_API void lua_arith(lua_State *L, int op)
Definition: lapi.c:311
LUA_API int luaB_opentests(lua_State *L)
#define cast_uchar(i)
Definition: llimits.h:131
#define lua_newtable(L)
Definition: lua.h:366
#define setsvalue2s(L, o, s)
Definition: lobject.h:353
LUA_API lua_State * lua_tothread(lua_State *L, int idx)
Definition: lapi.c:438
Instruction * code
Definition: lobject.h:543
#define lua_pushliteral(L, s)
Definition: lua.h:381
GCObject * finobjsur
Definition: lstate.h:287
#define G_OLD0
Definition: lgc.h:108
LUALIB_API lua_Integer luaL_len(lua_State *L, int idx)
Definition: lauxlib.c:849
LUALIB_API void luaL_unref(lua_State *L, int t, int ref)
Definition: lauxlib.c:667
LUALIB_API void luaL_checkany(lua_State *L, int arg)
Definition: lauxlib.c:396
struct Proto ** p
Definition: lobject.h:544
GCObject * weak
Definition: lstate.h:277
Node * node
Definition: lobject.h:718
lu_byte maxstacksize
Definition: lobject.h:532
GCObject * gray
Definition: lstate.h:275
j template void())
Definition: json.hpp:3707
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
Definition: lauxlib.c:380
LUA_API int lua_next(lua_State *L, int idx)
Definition: lapi.c:1220
#define ABSLINEINFO
Definition: ldebug.h:27
LUALIB_API const char * luaL_tolstring(lua_State *L, int idx, size_t *len)
Definition: lauxlib.c:861
#define tsvalue(o)
Definition: lobject.h:345
#define lua_isnil(L, n)
Definition: lua.h:375
#define lua_islightuserdata(L, n)
Definition: lua.h:374
LUA_API void lua_concat(lua_State *L, int n)
Definition: lapi.c:1253
#define lua_assert(c)
Definition: llimits.h:101
const char * name
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
Definition: lauxlib.c:442
LUALIB_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)
Definition: lauxlib.c:945
#define LUA_OPLE
Definition: lua.h:224
LUA_API void * lua_newuserdatauv(lua_State *L, size_t size, int nuvalue)
Definition: lapi.c:1311
#define GCSpropagate
Definition: lgc.h:31
#define GETARG_B(i)
Definition: lopcodes.h:128
#define gco2upv(o)
Definition: lstate.h:374
#define ttypename(x)
Definition: ltm.h:69
LUAMOD_API int luaopen_string(lua_State *L)
Definition: lstrlib.c:1800
#define LUA_NUMTAGS
Definition: lua.h:415
#define lua_isfunction(L, n)
Definition: lua.h:372
LUA_API int lua_absindex(lua_State *L, int idx)
Definition: lapi.c:161
unsigned long numblocks
Definition: ltests.h:55
LUA_API int lua_type(lua_State *L, int idx)
Definition: lapi.c:260
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
Definition: lapi.c:728
int size
Definition: lstate.h:186
TString ** hash
Definition: lstate.h:184
#define getOpMode(m)
Definition: lopcodes.h:370
struct Table * metatable
Definition: lobject.h:720
GCObject ** sweepgc
Definition: lstate.h:273
#define G_TOUCHED2
Definition: lgc.h:112
#define lua_longassert(c)
Definition: llimits.h:103
LUA_API void lua_callk(lua_State *L, int nargs, int nresults, lua_KContext ctx, lua_KFunction k)
Definition: lapi.c:971
struct Header Header
#define gco2ts(o)
Definition: lstate.h:364
#define lua_yield(L, n)
Definition: lua.h:305
#define lua_replace(L, idx)
Definition: lua.h:393
int sizek
Definition: lobject.h:534
GCObject * survival
Definition: lstate.h:283
GCObject * grayagain
Definition: lstate.h:276
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int arg, lua_Integer def)
Definition: lauxlib.c:452
#define G_OLD1
Definition: lgc.h:109
UpVal * openupval
Definition: lstate.h:316
LUAMOD_API int luaopen_math(lua_State *L)
Definition: lmathlib.c:750
#define lua_tostring(L, i)
Definition: lua.h:386
#define LUAI_IS32INT
Definition: luaconf.h:91
GCObject * allweak
Definition: lstate.h:279
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)
Definition: lapi.c:231
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
Definition: lapi.c:555
static void checkstack(lua_State *L, lua_State *L1, int n)
Definition: ldblib.c:35
MQTTClient c
Definition: test10.c:1656
#define LUA_VUPVAL
Definition: lobject.h:562
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.c:234
#define LUA_VPROTO
Definition: lobject.h:485
#define luaL_newlib(L, l)
Definition: lauxlib.h:129
#define checkliveness(L, obj)
Definition: lobject.h:102
#define lua_call(L, n, r)
Definition: lua.h:283
LUA_API void lua_rotate(lua_State *L, int idx, int n)
Definition: lapi.c:217
GCObject * fixedgc
Definition: lstate.h:281
#define luaL_argcheck(L, cond, arg, extramsg)
Definition: lauxlib.h:132
int sizecode
Definition: lobject.h:535
LUA_API lua_State * lua_newthread(lua_State *L)
Definition: lstate.c:321
TValue upvalue[1]
Definition: lobject.h:625
LUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud)
Definition: lapi.c:1277
union CallInfo::@30 u
#define ttisnumber(o)
Definition: lobject.h:302
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)
Definition: lauxlib.c:925
#define isblack(x)
Definition: lgc.h:88
#define isdummy(t)
Definition: ltable.h:27
#define G_NEW
Definition: lgc.h:106
#define iscollectable(o)
Definition: lobject.h:276
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
Definition: lapi.c:489
#define LUA_VLCL
Definition: lobject.h:566
#define LUA_REGISTRYINDEX
Definition: lua.h:44
GCObject * old1
Definition: lstate.h:284
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
Definition: lapi.c:592
LUALIB_API void luaL_checktype(lua_State *L, int arg, int t)
Definition: lauxlib.c:390
#define keyisnil(node)
Definition: lobject.h:731
#define sizenode(t)
Definition: lobject.h:766
struct CallInfo * previous
Definition: lstate.h:196
#define LUA_OK
Definition: lua.h:49
#define lua_istable(L, n)
Definition: lua.h:373
LUA_API void lua_len(lua_State *L, int idx)
Definition: lapi.c:1267
Node * lastfree
Definition: lobject.h:719
Definition: lobject.h:674
#define G_SURVIVAL
Definition: lgc.h:107
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int arg)
Definition: lauxlib.c:420
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
Definition: lapi.c:542
#define bitmask(b)
Definition: lgc.h:63
#define OFFSET_sBx
Definition: lopcodes.h:77
Definition: lobject.h:437
lu_byte gcstate
Definition: lstate.h:263
LUA_API const char * lua_setupvalue(lua_State *L, int funcindex, int n)
Definition: lapi.c:1366
#define lua_insert(L, idx)
Definition: lua.h:389
#define cast_int(i)
Definition: llimits.h:128
#define cast_sizet(i)
Definition: llimits.h:134
unsigned long objcount[LUA_NUMTYPES]
Definition: ltests.h:60
int stacksize
Definition: lstate.h:325
TString * name
Definition: lobject.h:492
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
Definition: lapi.c:502
#define G_OLD
Definition: lgc.h:110
#define KGC_INC
Definition: lstate.h:179
struct Proto * p
Definition: lobject.h:631
void lua_warning(lua_State *L, const char *msg, int tocont)
Definition: lapi.c:1303
struct TString * hnext
Definition: lobject.h:369
#define issweepphase(g)
Definition: lgc.h:42
LUAI_FUNC unsigned int luaH_realasize(const Table *t)
Definition: ltable.c:209
l_uint32 Instruction
Definition: llimits.h:194
unsigned int alimit
Definition: lobject.h:716
#define GETARG_sJ(i)
Definition: lopcodes.h:150
int line
Definition: lobject.h:522
Definition: lopcodes.h:32
int currentline
Definition: lua.h:476
#define isold(o)
Definition: lgc.h:118
int sizeupvalues
Definition: lobject.h:533
#define MAXARG_Bx
Definition: lopcodes.h:74
#define resetbit(x, b)
Definition: lgc.h:66
LUA_API int lua_getfield(lua_State *L, int idx, const char *k)
Definition: lapi.c:655
static const char *const opnames[]
Definition: lopnames.h:15
union TString::@20 u
TValue * k
Definition: lobject.h:542
struct UpVal::@22::@23 open
GCObject * ephemeron
Definition: lstate.h:278
#define GETARG_Bx(i)
Definition: lopcodes.h:140
#define novariant(t)
Definition: lobject.h:76
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
Definition: lapi.c:481
#define GCSenteratomic
Definition: lgc.h:32
#define LUA_TTABLE
Definition: lua.h:70
GCObject * reallyold
Definition: lstate.h:285
#define luaL_optstring(L, n, d)
Definition: lauxlib.h:139
#define isgray(x)
Definition: lgc.h:89
#define GCSswpallgc
Definition: lgc.h:34
#define isLua(ci)
Definition: lstate.h:238
LUA_NUMBER lua_Number
Definition: lua.h:90
#define G_TOUCHED1
Definition: lgc.h:111
#define LUA_TBOOLEAN
Definition: lua.h:66
#define LUA_MASKLINE
Definition: lua.h:441
#define LUA_OPEQ
Definition: lua.h:222
#define LUA_VUSERDATA
Definition: lobject.h:407
lu_byte numparams
Definition: lobject.h:530
GCObject * finobjrold
Definition: lstate.h:289
#define setobj2s(L, o1, o2)
Definition: lobject.h:127
LUA_API int lua_checkstack(lua_State *L, int n)
Definition: lapi.c:98
#define MEMERRMSG
Definition: lstring.h:19
LUA_API int lua_gettable(lua_State *L, int idx)
Definition: lapi.c:640
#define hvalue(o)
Definition: lobject.h:657
struct CallInfo::@30::@32 l
int luaG_getfuncline(const Proto *f, int pc)
Definition: ldebug.c:87
LUA_API int lua_gettop(lua_State *L)
Definition: lapi.c:168
#define EXTRA_STACK
Definition: lstate.h:172
LUA_API lua_Unsigned lua_rawlen(lua_State *L, int idx)
Definition: lapi.c:402
TValue l_registry
Definition: lstate.h:259
LUA_API Memcontrol l_memcontrol
Definition: ltests.h:63
#define luaL_checkstring(L, n)
Definition: lauxlib.h:138
#define GETARG_Ax(i)
Definition: lopcodes.h:143
unsigned long maxmem
Definition: ltests.h:57


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:09