The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lauxlib.cpp
Go to the documentation of this file.
1 /*
2 ** Auxiliary functions for building Lua libraries
3 ** See Copyright Notice in lua.h
4 */
5 
6 
7 #include <errno.h>
8 #include <stdarg.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
13 
14 /* This file uses only the official API of Lua.
15 ** Any function declared here could be written as an application function.
16 */
17 
18 #define lauxlib_c
19 #define LUA_LIB
20 
21 #include "lua.h"
22 
23 #include "lauxlib.h"
24 
25 
26 /*
27 ** {======================================================
28 ** Traceback
29 ** =======================================================
30 */
31 
32 
33 #define LEVELS1 12 /* size of the first part of the stack */
34 #define LEVELS2 10 /* size of the second part of the stack */
35 
36 
37 
38 /*
39 ** search for 'objidx' in table at index -1.
40 ** return 1 + string at top if find a good name.
41 */
42 static int findfield (lua_State *L, int objidx, int level) {
43  if (level == 0 || !lua_istable(L, -1))
44  return 0; /* not found */
45  lua_pushnil(L); /* start 'next' loop */
46  while (lua_next(L, -2)) { /* for each pair in table */
47  if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
48  if (lua_rawequal(L, objidx, -1)) { /* found object? */
49  lua_pop(L, 1); /* remove value (but keep name) */
50  return 1;
51  }
52  else if (findfield(L, objidx, level - 1)) { /* try recursively */
53  lua_remove(L, -2); /* remove table (but keep name) */
54  lua_pushliteral(L, ".");
55  lua_insert(L, -2); /* place '.' between the two names */
56  lua_concat(L, 3);
57  return 1;
58  }
59  }
60  lua_pop(L, 1); /* remove value */
61  }
62  return 0; /* not found */
63 }
64 
65 
66 static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
67  int top = lua_gettop(L);
68  lua_getinfo(L, "f", ar); /* push function */
70  if (findfield(L, top + 1, 2)) {
71  lua_copy(L, -1, top + 1); /* move name to proper place */
72  lua_pop(L, 2); /* remove pushed values */
73  return 1;
74  }
75  else {
76  lua_settop(L, top); /* remove function and global table */
77  return 0;
78  }
79 }
80 
81 
82 static void pushfuncname (lua_State *L, lua_Debug *ar) {
83  if (*ar->namewhat != '\0') /* is there a name? */
84  lua_pushfstring(L, "function " LUA_QS, ar->name);
85  else if (*ar->what == 'm') /* main? */
86  lua_pushliteral(L, "main chunk");
87  else if (*ar->what == 'C') {
88  if (pushglobalfuncname(L, ar)) {
89  lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
90  lua_remove(L, -2); /* remove name */
91  }
92  else
93  lua_pushliteral(L, "?");
94  }
95  else
96  lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
97 }
98 
99 
100 static int countlevels (lua_State *L) {
101  lua_Debug ar;
102  int li = 1, le = 1;
103  /* find an upper bound */
104  while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
105  /* do a binary search */
106  while (li < le) {
107  int m = (li + le)/2;
108  if (lua_getstack(L, m, &ar)) li = m + 1;
109  else le = m;
110  }
111  return le - 1;
112 }
113 
114 
116  const char *msg, int level) {
117  lua_Debug ar;
118  int top = lua_gettop(L);
119  int numlevels = countlevels(L1);
120  int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
121  if (msg) lua_pushfstring(L, "%s\n", msg);
122  lua_pushliteral(L, "stack traceback:");
123  while (lua_getstack(L1, level++, &ar)) {
124  if (level == mark) { /* too many levels? */
125  lua_pushliteral(L, "\n\t..."); /* add a '...' */
126  level = numlevels - LEVELS2; /* and skip to last ones */
127  }
128  else {
129  lua_getinfo(L1, "Slnt", &ar);
130  lua_pushfstring(L, "\n\t%s:", ar.short_src);
131  if (ar.currentline > 0)
132  lua_pushfstring(L, "%d:", ar.currentline);
133  lua_pushliteral(L, " in ");
134  pushfuncname(L, &ar);
135  if (ar.istailcall)
136  lua_pushliteral(L, "\n\t(...tail calls...)");
137  lua_concat(L, lua_gettop(L) - top);
138  }
139  }
140  lua_concat(L, lua_gettop(L) - top);
141 }
142 
143 /* }====================================================== */
144 
145 
146 /*
147 ** {======================================================
148 ** Error-report functions
149 ** =======================================================
150 */
151 
152 LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
153  lua_Debug ar;
154  if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
155  return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
156  lua_getinfo(L, "n", &ar);
157  if (strcmp(ar.namewhat, "method") == 0) {
158  narg--; /* do not count `self' */
159  if (narg == 0) /* error is in the self argument itself? */
160  return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
161  ar.name, extramsg);
162  }
163  if (ar.name == NULL)
164  ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
165  return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
166  narg, ar.name, extramsg);
167 }
168 
169 
170 static int typeerror (lua_State *L, int narg, const char *tname) {
171  const char *msg = lua_pushfstring(L, "%s expected, got %s",
172  tname, luaL_typename(L, narg));
173  return luaL_argerror(L, narg, msg);
174 }
175 
176 LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
177  return typeerror(L, narg, tname);
178 }
179 
180 static void tag_error (lua_State *L, int narg, int tag) {
181  typeerror(L, narg, lua_typename(L, tag));
182 }
183 
184 
186  lua_Debug ar;
187  if (lua_getstack(L, level, &ar)) { /* check function at level */
188  lua_getinfo(L, "Sl", &ar); /* get info about it */
189  if (ar.currentline > 0) { /* is there info? */
190  lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
191  return;
192  }
193  }
194  lua_pushliteral(L, ""); /* else, no information available... */
195 }
196 
197 
198 LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
199  va_list argp;
200  va_start(argp, fmt);
201  luaL_where(L, 1);
202  lua_pushvfstring(L, fmt, argp);
203  va_end(argp);
204  lua_concat(L, 2);
205  return lua_error(L);
206 }
207 
208 
209 LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
210  int en = errno; /* calls to Lua API may change this value */
211  if (stat) {
212  lua_pushboolean(L, 1);
213  return 1;
214  }
215  else {
216  lua_pushnil(L);
217  if (fname)
218  lua_pushfstring(L, "%s: %s", fname, strerror(en));
219  else
220  lua_pushstring(L, strerror(en));
221  lua_pushinteger(L, en);
222  return 3;
223  }
224 }
225 
226 
227 #if !defined(inspectstat) /* { */
228 
229 #if defined(LUA_USE_POSIX)
230 
231 #include <sys/wait.h>
232 
233 /*
234 ** use appropriate macros to interpret 'pclose' return status
235 */
236 #define inspectstat(stat,what) \
237  if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \
238  else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; }
239 
240 #else
241 
242 #define inspectstat(stat,what) /* no op */
243 
244 #endif
245 
246 #endif /* } */
247 
248 
250  const char *what = "exit"; /* type of termination */
251  if (stat == -1) /* error? */
252  return luaL_fileresult(L, 0, NULL);
253  else {
254  inspectstat(stat, what); /* interpret result */
255  if (*what == 'e' && stat == 0) /* successful termination? */
256  lua_pushboolean(L, 1);
257  else
258  lua_pushnil(L);
259  lua_pushstring(L, what);
260  lua_pushinteger(L, stat);
261  return 3; /* return true/nil,what,code */
262  }
263 }
264 
265 /* }====================================================== */
266 
267 
268 /*
269 ** {======================================================
270 ** Userdata's metatable manipulation
271 ** =======================================================
272 */
273 
274 LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
275  luaL_getmetatable(L, tname); /* try to get metatable */
276  if (!lua_isnil(L, -1)) /* name already in use? */
277  return 0; /* leave previous value on top, but return 0 */
278  lua_pop(L, 1);
279  lua_newtable(L); /* create metatable */
280  lua_pushvalue(L, -1);
281  lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
282  return 1;
283 }
284 
285 
286 LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
287  luaL_getmetatable(L, tname);
288  lua_setmetatable(L, -2);
289 }
290 
291 
292 LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
293  void *p = lua_touserdata(L, ud);
294  if (p != NULL) { /* value is a userdata? */
295  if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
296  luaL_getmetatable(L, tname); /* get correct metatable */
297  if (!lua_rawequal(L, -1, -2)) /* not the same? */
298  p = NULL; /* value is a userdata with wrong metatable */
299  lua_pop(L, 2); /* remove both metatables */
300  return p;
301  }
302  }
303  return NULL; /* value is not a userdata with a metatable */
304 }
305 
306 
307 LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
308  void *p = luaL_testudata(L, ud, tname);
309  if (p == NULL) typeerror(L, ud, tname);
310  return p;
311 }
312 
313 /* }====================================================== */
314 
315 
316 /*
317 ** {======================================================
318 ** Argument check functions
319 ** =======================================================
320 */
321 
322 LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,
323  const char *const lst[]) {
324  const char *name = (def) ? luaL_optstring(L, narg, def) :
325  luaL_checkstring(L, narg);
326  int i;
327  for (i=0; lst[i]; i++)
328  if (strcmp(lst[i], name) == 0)
329  return i;
330  return luaL_argerror(L, narg,
331  lua_pushfstring(L, "invalid option " LUA_QS, name));
332 }
333 
334 
335 LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {
336  /* keep some extra space to run error routines, if needed */
337  const int extra = LUA_MINSTACK;
338  if (!lua_checkstack(L, space + extra)) {
339  if (msg)
340  luaL_error(L, "stack overflow (%s)", msg);
341  else
342  luaL_error(L, "stack overflow");
343  }
344 }
345 
346 
347 LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {
348  if (lua_type(L, narg) != t)
349  tag_error(L, narg, t);
350 }
351 
352 
353 LUALIB_API void luaL_checkany (lua_State *L, int narg) {
354  if (lua_type(L, narg) == LUA_TNONE)
355  luaL_argerror(L, narg, "value expected");
356 }
357 
358 
359 LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
360  const char *s = lua_tolstring(L, narg, len);
361  if (!s) tag_error(L, narg, LUA_TSTRING);
362  return s;
363 }
364 
365 
366 LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
367  const char *def, size_t *len) {
368  if (lua_isnoneornil(L, narg)) {
369  if (len)
370  *len = (def ? strlen(def) : 0);
371  return def;
372  }
373  else return luaL_checklstring(L, narg, len);
374 }
375 
376 
378  int isnum;
379  lua_Number d = lua_tonumberx(L, narg, &isnum);
380  if (!isnum)
381  tag_error(L, narg, LUA_TNUMBER);
382  return d;
383 }
384 
385 
387  return luaL_opt(L, luaL_checknumber, narg, def);
388 }
389 
390 
392  int isnum;
393  lua_Integer d = lua_tointegerx(L, narg, &isnum);
394  if (!isnum)
395  tag_error(L, narg, LUA_TNUMBER);
396  return d;
397 }
398 
399 
401  int isnum;
402  lua_Unsigned d = lua_tounsignedx(L, narg, &isnum);
403  if (!isnum)
404  tag_error(L, narg, LUA_TNUMBER);
405  return d;
406 }
407 
408 
410  lua_Integer def) {
411  return luaL_opt(L, luaL_checkinteger, narg, def);
412 }
413 
414 
416  lua_Unsigned def) {
417  return luaL_opt(L, luaL_checkunsigned, narg, def);
418 }
419 
420 /* }====================================================== */
421 
422 
423 /*
424 ** {======================================================
425 ** Generic Buffer manipulation
426 ** =======================================================
427 */
428 
429 /*
430 ** check whether buffer is using a userdata on the stack as a temporary
431 ** buffer
432 */
433 #define buffonstack(B) ((B)->b != (B)->initb)
434 
435 
436 /*
437 ** returns a pointer to a free area with at least 'sz' bytes
438 */
439 LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
440  lua_State *L = B->L;
441  if (B->size - B->n < sz) { /* not enough space? */
442  char *newbuff;
443  size_t newsize = B->size * 2; /* double buffer size */
444  if (newsize - B->n < sz) /* not big enough? */
445  newsize = B->n + sz;
446  if (newsize < B->n || newsize - B->n < sz)
447  luaL_error(L, "buffer too large");
448  /* create larger buffer */
449  newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char));
450  /* move content to new buffer */
451  memcpy(newbuff, B->b, B->n * sizeof(char));
452  if (buffonstack(B))
453  lua_remove(L, -2); /* remove old buffer */
454  B->b = newbuff;
455  B->size = newsize;
456  }
457  return &B->b[B->n];
458 }
459 
460 
461 LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
462  char *b = luaL_prepbuffsize(B, l);
463  memcpy(b, s, l * sizeof(char));
464  luaL_addsize(B, l);
465 }
466 
467 
468 LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
469  luaL_addlstring(B, s, strlen(s));
470 }
471 
472 
474  lua_State *L = B->L;
475  lua_pushlstring(L, B->b, B->n);
476  if (buffonstack(B))
477  lua_remove(L, -2); /* remove old buffer */
478 }
479 
480 
482  luaL_addsize(B, sz);
483  luaL_pushresult(B);
484 }
485 
486 
488  lua_State *L = B->L;
489  size_t l;
490  const char *s = lua_tolstring(L, -1, &l);
491  if (buffonstack(B))
492  lua_insert(L, -2); /* put value below buffer */
493  luaL_addlstring(B, s, l);
494  lua_remove(L, (buffonstack(B)) ? -2 : -1); /* remove value */
495 }
496 
497 
499  B->L = L;
500  B->b = B->initb;
501  B->n = 0;
502  B->size = LUAL_BUFFERSIZE;
503 }
504 
505 
507  luaL_buffinit(L, B);
508  return luaL_prepbuffsize(B, sz);
509 }
510 
511 /* }====================================================== */
512 
513 
514 /*
515 ** {======================================================
516 ** Reference system
517 ** =======================================================
518 */
519 
520 /* index of free-list header */
521 #define freelist 0
522 
523 
525  int ref;
526  if (lua_isnil(L, -1)) {
527  lua_pop(L, 1); /* remove from stack */
528  return LUA_REFNIL; /* `nil' has a unique fixed reference */
529  }
530  t = lua_absindex(L, t);
531  lua_rawgeti(L, t, freelist); /* get first free element */
532  ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
533  lua_pop(L, 1); /* remove it from stack */
534  if (ref != 0) { /* any free element? */
535  lua_rawgeti(L, t, ref); /* remove it from list */
536  lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
537  }
538  else /* no free elements */
539  ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
540  lua_rawseti(L, t, ref);
541  return ref;
542 }
543 
544 
545 LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
546  if (ref >= 0) {
547  t = lua_absindex(L, t);
548  lua_rawgeti(L, t, freelist);
549  lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
550  lua_pushinteger(L, ref);
551  lua_rawseti(L, t, freelist); /* t[freelist] = ref */
552  }
553 }
554 
555 /* }====================================================== */
556 
557 
558 /*
559 ** {======================================================
560 ** Load functions
561 ** =======================================================
562 */
563 
564 typedef struct LoadF {
565  int n; /* number of pre-read characters */
566  FILE *f; /* file being read */
567  char buff[LUAL_BUFFERSIZE]; /* area for reading file */
568 } LoadF;
569 
570 
571 static const char *getF (lua_State *L, void *ud, size_t *size) {
572  LoadF *lf = (LoadF *)ud;
573  (void)L; /* not used */
574  if (lf->n > 0) { /* are there pre-read characters to be read? */
575  *size = lf->n; /* return them (chars already in buffer) */
576  lf->n = 0; /* no more pre-read characters */
577  }
578  else { /* read a block from file */
579  /* 'fread' can return > 0 *and* set the EOF flag. If next call to
580  'getF' called 'fread', it might still wait for user input.
581  The next check avoids this problem. */
582  if (feof(lf->f)) return NULL;
583  *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
584  }
585  return lf->buff;
586 }
587 
588 
589 static int errfile (lua_State *L, const char *what, int fnameindex) {
590  const char *serr = strerror(errno);
591  const char *filename = lua_tostring(L, fnameindex) + 1;
592  lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
593  lua_remove(L, fnameindex);
594  return LUA_ERRFILE;
595 }
596 
597 
598 static int skipBOM (LoadF *lf) {
599  const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
600  int c;
601  lf->n = 0;
602  do {
603  c = getc(lf->f);
604  if (c == EOF || c != *(const unsigned char *)p++) return c;
605  lf->buff[lf->n++] = c; /* to be read by the parser */
606  } while (*p != '\0');
607  lf->n = 0; /* prefix matched; discard it */
608  return getc(lf->f); /* return next character */
609 }
610 
611 
612 /*
613 ** reads the first character of file 'f' and skips an optional BOM mark
614 ** in its beginning plus its first line if it starts with '#'. Returns
615 ** true if it skipped the first line. In any case, '*cp' has the
616 ** first "valid" character of the file (after the optional BOM and
617 ** a first-line comment).
618 */
619 static int skipcomment (LoadF *lf, int *cp) {
620  int c = *cp = skipBOM(lf);
621  if (c == '#') { /* first line is a comment (Unix exec. file)? */
622  do { /* skip first line */
623  c = getc(lf->f);
624  } while (c != EOF && c != '\n') ;
625  *cp = getc(lf->f); /* skip end-of-line, if present */
626  return 1; /* there was a comment */
627  }
628  else return 0; /* no comment */
629 }
630 
631 
632 LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
633  const char *mode) {
634  LoadF lf;
635  int status, readstatus;
636  int c;
637  int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
638  if (filename == NULL) {
639  lua_pushliteral(L, "=stdin");
640  lf.f = stdin;
641  }
642  else {
643  lua_pushfstring(L, "@%s", filename);
644  lf.f = fopen(filename, "r");
645  if (lf.f == NULL) return errfile(L, "open", fnameindex);
646  }
647  if (skipcomment(&lf, &c)) /* read initial portion */
648  lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
649  if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
650  lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
651  if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
652  skipcomment(&lf, &c); /* re-read initial portion */
653  }
654  if (c != EOF)
655  lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
656  status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
657  readstatus = ferror(lf.f);
658  if (filename) fclose(lf.f); /* close file (even in case of errors) */
659  if (readstatus) {
660  lua_settop(L, fnameindex); /* ignore results from `lua_load' */
661  return errfile(L, "read", fnameindex);
662  }
663  lua_remove(L, fnameindex);
664  return status;
665 }
666 
667 
668 typedef struct LoadS {
669  const char *s;
670  size_t size;
671 } LoadS;
672 
673 
674 static const char *getS (lua_State *L, void *ud, size_t *size) {
675  LoadS *ls = (LoadS *)ud;
676  (void)L; /* not used */
677  if (ls->size == 0) return NULL;
678  *size = ls->size;
679  ls->size = 0;
680  return ls->s;
681 }
682 
683 
684 LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,
685  const char *name, const char *mode) {
686  LoadS ls;
687  ls.s = buff;
688  ls.size = size;
689  return lua_load(L, getS, &ls, name, mode);
690 }
691 
692 
693 LUALIB_API int luaL_loadstring (lua_State *L, const char *s) {
694  return luaL_loadbuffer(L, s, strlen(s), s);
695 }
696 
697 /* }====================================================== */
698 
699 
700 
701 LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
702  if (!lua_getmetatable(L, obj)) /* no metatable? */
703  return 0;
704  lua_pushstring(L, event);
705  lua_rawget(L, -2);
706  if (lua_isnil(L, -1)) {
707  lua_pop(L, 2); /* remove metatable and metafield */
708  return 0;
709  }
710  else {
711  lua_remove(L, -2); /* remove only metatable */
712  return 1;
713  }
714 }
715 
716 
717 LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
718  obj = lua_absindex(L, obj);
719  if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
720  return 0;
721  lua_pushvalue(L, obj);
722  lua_call(L, 1, 1);
723  return 1;
724 }
725 
726 
727 LUALIB_API int luaL_len (lua_State *L, int idx) {
728  int l;
729  int isnum;
730  lua_len(L, idx);
731  l = (int)lua_tointegerx(L, -1, &isnum);
732  if (!isnum)
733  luaL_error(L, "object length is not a number");
734  lua_pop(L, 1); /* remove object */
735  return l;
736 }
737 
738 
739 LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
740  if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
741  switch (lua_type(L, idx)) {
742  case LUA_TNUMBER:
743  case LUA_TSTRING:
744  lua_pushvalue(L, idx);
745  break;
746  case LUA_TBOOLEAN:
747  lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
748  break;
749  case LUA_TNIL:
750  lua_pushliteral(L, "nil");
751  break;
752  default:
753  lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
754  lua_topointer(L, idx));
755  break;
756  }
757  }
758  return lua_tolstring(L, -1, len);
759 }
760 
761 
762 /*
763 ** {======================================================
764 ** Compatibility with 5.1 module functions
765 ** =======================================================
766 */
767 #if defined(LUA_COMPAT_MODULE)
768 
769 static const char *luaL_findtable (lua_State *L, int idx,
770  const char *fname, int szhint) {
771  const char *e;
772  if (idx) lua_pushvalue(L, idx);
773  do {
774  e = strchr(fname, '.');
775  if (e == NULL) e = fname + strlen(fname);
776  lua_pushlstring(L, fname, e - fname);
777  lua_rawget(L, -2);
778  if (lua_isnil(L, -1)) { /* no such field? */
779  lua_pop(L, 1); /* remove this nil */
780  lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
781  lua_pushlstring(L, fname, e - fname);
782  lua_pushvalue(L, -2);
783  lua_settable(L, -4); /* set new table into field */
784  }
785  else if (!lua_istable(L, -1)) { /* field has a non-table value? */
786  lua_pop(L, 2); /* remove table and value */
787  return fname; /* return problematic part of the name */
788  }
789  lua_remove(L, -2); /* remove previous table */
790  fname = e + 1;
791  } while (*e == '.');
792  return NULL;
793 }
794 
795 
796 /*
797 ** Count number of elements in a luaL_Reg list.
798 */
799 static int libsize (const luaL_Reg *l) {
800  int size = 0;
801  for (; l && l->name; l++) size++;
802  return size;
803 }
804 
805 
806 /*
807 ** Find or create a module table with a given name. The function
808 ** first looks at the _LOADED table and, if that fails, try a
809 ** global variable with that name. In any case, leaves on the stack
810 ** the module table.
811 */
812 LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
813  int sizehint) {
814  luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */
815  lua_getfield(L, -1, modname); /* get _LOADED[modname] */
816  if (!lua_istable(L, -1)) { /* not found? */
817  lua_pop(L, 1); /* remove previous result */
818  /* try global variable (and create one if it does not exist) */
820  if (luaL_findtable(L, 0, modname, sizehint) != NULL)
821  luaL_error(L, "name conflict for module " LUA_QS, modname);
822  lua_pushvalue(L, -1);
823  lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */
824  }
825  lua_remove(L, -2); /* remove _LOADED table */
826 }
827 
828 
829 LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
830  const luaL_Reg *l, int nup) {
832  if (libname) {
833  luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */
834  lua_insert(L, -(nup + 1)); /* move library table to below upvalues */
835  }
836  if (l)
837  luaL_setfuncs(L, l, nup);
838  else
839  lua_pop(L, nup); /* remove upvalues */
840 }
841 
842 #endif
843 /* }====================================================== */
844 
845 /*
846 ** set functions from list 'l' into table at top - 'nup'; each
847 ** function gets the 'nup' elements at the top as upvalues.
848 ** Returns with only the table at the stack.
849 */
850 LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
852  luaL_checkstack(L, nup, "too many upvalues");
853  for (; l->name != NULL; l++) { /* fill the table with given functions */
854  int i;
855  for (i = 0; i < nup; i++) /* copy upvalues to the top */
856  lua_pushvalue(L, -nup);
857  lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
858  lua_setfield(L, -(nup + 2), l->name);
859  }
860  lua_pop(L, nup); /* remove upvalues */
861 }
862 
863 
864 /*
865 ** ensure that stack[idx][fname] has a table and push that table
866 ** into the stack
867 */
868 LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {
869  lua_getfield(L, idx, fname);
870  if (lua_istable(L, -1)) return 1; /* table already there */
871  else {
872  lua_pop(L, 1); /* remove previous result */
873  idx = lua_absindex(L, idx);
874  lua_newtable(L);
875  lua_pushvalue(L, -1); /* copy to be left at top */
876  lua_setfield(L, idx, fname); /* assign new table to field */
877  return 0; /* false, because did not find table there */
878  }
879 }
880 
881 
882 /*
883 ** stripped-down 'require'. Calls 'openf' to open a module,
884 ** registers the result in 'package.loaded' table and, if 'glb'
885 ** is true, also registers the result in the global table.
886 ** Leaves resulting module on the top.
887 */
888 LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
889  lua_CFunction openf, int glb) {
890  lua_pushcfunction(L, openf);
891  lua_pushstring(L, modname); /* argument to open function */
892  lua_call(L, 1, 1); /* open module */
893  luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
894  lua_pushvalue(L, -2); /* make copy of module (call result) */
895  lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
896  lua_pop(L, 1); /* remove _LOADED table */
897  if (glb) {
898  lua_pushvalue(L, -1); /* copy of 'mod' */
899  lua_setglobal(L, modname); /* _G[modname] = module */
900  }
901 }
902 
903 
904 LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
905  const char *r) {
906  const char *wild;
907  size_t l = strlen(p);
908  luaL_Buffer b;
909  luaL_buffinit(L, &b);
910  while ((wild = strstr(s, p)) != NULL) {
911  luaL_addlstring(&b, s, wild - s); /* push prefix */
912  luaL_addstring(&b, r); /* push replacement in place of pattern */
913  s = wild + l; /* continue after `p' */
914  }
915  luaL_addstring(&b, s); /* push last suffix */
916  luaL_pushresult(&b);
917  return lua_tostring(L, -1);
918 }
919 
920 
921 static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
922  (void)ud; (void)osize; /* not used */
923  if (nsize == 0) {
924  free(ptr);
925  return NULL;
926  }
927  else
928  return realloc(ptr, nsize);
929 }
930 
931 
932 static int panic (lua_State *L) {
933  luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
934  lua_tostring(L, -1));
935  return 0; /* return to Lua to abort */
936 }
937 
938 
940  lua_State *L = lua_newstate(l_alloc, NULL);
941  if (L) lua_atpanic(L, &panic);
942  return L;
943 }
944 
945 
947  const lua_Number *v = lua_version(L);
948  if (v != lua_version(NULL))
949  luaL_error(L, "multiple Lua VMs detected");
950  else if (*v != ver)
951  luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
952  ver, *v);
953  /* check conversions number -> integer types */
954  lua_pushnumber(L, -(lua_Number)0x1234);
955  if (lua_tointeger(L, -1) != -0x1234 ||
956  lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)
957  luaL_error(L, "bad conversion number->int;"
958  " must recompile Lua with proper settings");
959  lua_pop(L, 1);
960 }
961 
const char * what
Definition: lua.h:402
#define luaL_addsize(B, s)
Definition: lauxlib.h:156
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
Definition: lapi.cpp:643
LUALIB_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)
Definition: lauxlib.cpp:888
#define lua_isnoneornil(L, n)
Definition: lua.h:337
Definition: lua.h:398
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
Definition: lauxlib.cpp:487
size_t size
Definition: lauxlib.h:145
LUALIB_API void * luaL_checkudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.cpp:307
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
Definition: lapi.cpp:667
#define lua_pushcfunction(L, f)
Definition: lua.h:328
size_t size
Definition: lauxlib.cpp:670
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:622
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
Definition: lauxlib.cpp:391
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
LUALIB_API lua_State * luaL_newstate(void)
Definition: lauxlib.cpp:939
LUALIB_API const char * luaL_tolstring(lua_State *L, int idx, size_t *len)
Definition: lauxlib.cpp:739
LUA_API void lua_settop(lua_State *L, int idx)
Definition: lapi.cpp:159
const char * s
Definition: lauxlib.cpp:669
LUA_API int lua_type(lua_State *L, int idx)
Definition: lapi.cpp:243
#define buffonstack(B)
Definition: lauxlib.cpp:433
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
Definition: lauxlib.cpp:439
GLint level
Definition: glew.h:1220
LUALIB_API int luaL_loadstring(lua_State *L, const char *s)
Definition: lauxlib.cpp:693
LUALIB_API const char * luaL_optlstring(lua_State *L, int narg, const char *def, size_t *len)
Definition: lauxlib.cpp:366
static const char * luaL_findtable(lua_State *L, int idx, const char *fname, int szhint)
Definition: lauxlib.cpp:769
const GLfloat * c
Definition: glew.h:12741
LUA_API void lua_pushboolean(lua_State *L, int b)
Definition: lapi.cpp:571
LUALIB_API int luaL_ref(lua_State *L, int t)
Definition: lauxlib.cpp:524
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)
Definition: lauxlib.cpp:868
static int errfile(lua_State *L, const char *what, int fnameindex)
Definition: lauxlib.cpp:589
const char * name
Definition: lua.h:400
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
Definition: lauxlib.cpp:347
const char * name
Definition: lauxlib.h:23
char buff[LUAL_BUFFERSIZE]
Definition: lauxlib.cpp:567
#define LEVELS1
Definition: lauxlib.cpp:33
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
Definition: lauxlib.cpp:473
LUALIB_API int luaL_getmetafield(lua_State *L, int obj, const char *event)
Definition: lauxlib.cpp:701
LUA_API int lua_gettop(lua_State *L)
Definition: lapi.cpp:154
#define LUA_ERRFILE
Definition: lauxlib.h:19
LUA_API const lua_Number * lua_version(lua_State *L)
Definition: lapi.cpp:131
static const char * getS(lua_State *L, void *ud, size_t *size)
Definition: lauxlib.cpp:674
static int skipcomment(LoadF *lf, int *cp)
Definition: lauxlib.cpp:619
LUA_API void lua_settable(lua_State *L, int idx)
Definition: lapi.cpp:741
#define lua_tointeger(L, i)
Definition: lua.h:319
static int countlevels(lua_State *L)
Definition: lauxlib.cpp:100
#define luaL_getmetatable(L, n)
Definition: lauxlib.h:130
LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode)
Definition: lauxlib.cpp:632
const char * what() const
#define luaL_typename(L, i)
Definition: lauxlib.h:122
char short_src[LUA_IDSIZE]
Definition: lua.h:411
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
Definition: lauxlib.cpp:335
LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)
Definition: lauxlib.cpp:468
const char * namewhat
Definition: lua.h:401
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
Definition: lapi.cpp:549
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
Definition: ldebug.cpp:82
#define d
FILE * f
Definition: lauxlib.cpp:566
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
Definition: lauxlib.cpp:286
GLenum mode
Definition: glew.h:2390
#define LUA_SIGNATURE
Definition: lua.h:30
GLdouble GLdouble t
Definition: glew.h:1366
#define freelist
Definition: lauxlib.cpp:521
LUA_API int lua_absindex(lua_State *L, int idx)
Definition: lapi.cpp:147
char initb[LUAL_BUFFERSIZE]
Definition: lauxlib.h:148
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
Definition: lauxlib.cpp:409
LUA_API void * lua_newuserdata(lua_State *L, size_t size)
Definition: lapi.cpp:1169
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:55
#define lua_pop(L, n)
Definition: lua.h:322
static int pushglobalfuncname(lua_State *L, lua_Debug *ar)
Definition: lauxlib.cpp:66
#define luaL_loadbuffer(L, s, sz, n)
Definition: lauxlib.h:134
GLdouble l
Definition: glew.h:6966
lua_CFunction func
Definition: lauxlib.h:24
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
LUA_API lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum)
Definition: lapi.cpp:343
LUALIB_API void luaL_pushresultsize(luaL_Buffer *B, size_t sz)
Definition: lauxlib.cpp:481
LUA_INTEGER lua_Integer
Definition: lua.h:106
#define LUA_TSTRING
Definition: lua.h:81
#define LUAL_BUFFERSIZE
Definition: luaconf.h:382
LUA_API void lua_setglobal(lua_State *L, const char *var)
Definition: lapi.cpp:728
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
Definition: lauxlib.cpp:209
LUALIB_API const char * luaL_gsub(lua_State *L, const char *s, const char *p, const char *r)
Definition: lauxlib.cpp:904
#define LUA_TNONE
Definition: lua.h:75
LUALIB_API int luaL_checkoption(lua_State *L, int narg, const char *def, const char *const lst[])
Definition: lauxlib.cpp:322
LUA_API int lua_rawequal(lua_State *L, int index1, int index2)
Definition: lapi.cpp:280
char istailcall
Definition: lua.h:410
LUA_API lua_Unsigned lua_tounsignedx(lua_State *L, int idx, int *isnum)
Definition: lapi.cpp:360
LUALIB_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t size, const char *name, const char *mode)
Definition: lauxlib.cpp:684
#define LUA_TNIL
Definition: lua.h:77
#define luaL_opt(L, f, n, d)
Definition: lauxlib.h:132
LUA_API int lua_toboolean(lua_State *L, int idx)
Definition: lapi.cpp:377
const GLdouble * v
Definition: glew.h:1359
static void * l_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
Definition: lauxlib.cpp:921
#define inspectstat(stat, what)
Definition: lauxlib.cpp:242
GLenum GLsizei len
Definition: glew.h:5662
#define lua_pushglobaltable(L)
Definition: lua.h:342
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
Definition: lauxlib.cpp:498
static void tag_error(lua_State *L, int narg, int tag)
Definition: lauxlib.cpp:180
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
Definition: lapi.cpp:495
#define LUA_TNUMBER
Definition: lua.h:80
LUALIB_API void luaL_where(lua_State *L, int level)
Definition: lauxlib.cpp:185
LUA_API int lua_getmetatable(lua_State *L, int objindex)
Definition: lapi.cpp:680
GLhandleARB obj
Definition: glew.h:4486
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg)
Definition: lauxlib.cpp:377
LUA_API int lua_setmetatable(lua_State *L, int objindex)
Definition: lapi.cpp:806
struct LoadF LoadF
LUA_API void lua_remove(lua_State *L, int idx)
Definition: lapi.cpp:176
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
Definition: lapi.cpp:383
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.cpp:292
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)
Definition: lauxlib.cpp:717
GLfloat GLfloat p
Definition: glew.h:12766
#define lua_tounsigned(L, i)
Definition: lua.h:320
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
LUALIB_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level)
Definition: lauxlib.cpp:115
LUALIB_API lua_Unsigned luaL_optunsigned(lua_State *L, int narg, lua_Unsigned def)
Definition: lauxlib.cpp:415
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum)
Definition: lapi.cpp:329
#define lua_newtable(L)
Definition: lua.h:324
LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)
Definition: lauxlib.cpp:461
LUA_API void lua_pushnil(lua_State *L)
Definition: lapi.cpp:459
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
Definition: lapi.cpp:467
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
Definition: lauxlib.cpp:359
LUA_API void lua_len(lua_State *L, int idx)
Definition: lapi.cpp:1141
#define lua_pushliteral(L, s)
Definition: lua.h:339
LUALIB_API lua_Number luaL_optnumber(lua_State *L, int narg, lua_Number def)
Definition: lauxlib.cpp:386
lua_State * L
Definition: lauxlib.h:147
size_t n
Definition: lauxlib.h:146
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
Definition: lauxlib.cpp:274
LUA_API void * lua_touserdata(lua_State *L, int idx)
Definition: lapi.cpp:421
#define luaL_checkversion(L)
Definition: lauxlib.h:29
#define lua_isnil(L, n)
Definition: lua.h:333
#define LUA_QS
Definition: luaconf.h:199
int n
Definition: lauxlib.cpp:565
const std::string space
whitespace is possible
#define LEVELS2
Definition: lauxlib.cpp:34
LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
Definition: ldebug.cpp:265
LUALIB_API lua_Unsigned luaL_checkunsigned(lua_State *L, int narg)
Definition: lauxlib.cpp:400
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname, const char *mode)
Definition: lapi.cpp:967
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
Definition: lauxlib.cpp:152
size_t i
Definition: function.cpp:1057
#define lua_tostring(L, i)
Definition: lua.h:345
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:112
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
Definition: lapi.cpp:778
static const char * getF(lua_State *L, void *ud, size_t *size)
Definition: lauxlib.cpp:571
LUA_API lua_State * lua_newstate(lua_Alloc f, void *ud)
Definition: lstate.cpp:265
#define LUA_MINSTACK
Definition: lua.h:92
LUA_API void lua_insert(lua_State *L, int idx)
Definition: lapi.cpp:187
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
LUA_API void lua_pushvalue(lua_State *L, int idx)
Definition: lapi.cpp:229
LUA_API const char * lua_pushvfstring(lua_State *L, const char *fmt, va_list argp)
Definition: lapi.cpp:525
LUA_UNSIGNED lua_Unsigned
Definition: lua.h:109
#define lua_call(L, n, r)
Definition: lua.h:252
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.cpp:198
#define luai_writestringerror(s, p)
Definition: luaconf.h:232
GLuint const GLchar * name
Definition: glew.h:1782
static int libsize(const luaL_Reg *l)
Definition: lauxlib.cpp:799
LUA_API size_t lua_rawlen(lua_State *L, int idx)
Definition: lapi.cpp:401
GLsizeiptr size
Definition: glew.h:1649
#define LUA_REGISTRYINDEX
Definition: lua.h:39
LUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf)
Definition: lapi.cpp:121
GLclampd n
Definition: glew.h:5903
LUA_API int lua_error(lua_State *L)
Definition: lapi.cpp:1099
GLenum GLint ref
Definition: glew.h:1813
LUA_API const void * lua_topointer(lua_State *L, int idx)
Definition: lapi.cpp:437
LUALIB_API char * luaL_buffinitsize(lua_State *L, luaL_Buffer *B, size_t sz)
Definition: lauxlib.cpp:506
const GLdouble * m
Definition: glew.h:6968
LUALIB_API void luaL_checkversion_(lua_State *L, lua_Number ver)
Definition: lauxlib.cpp:946
#define lua_istable(L, n)
Definition: lua.h:331
LUA_API void lua_concat(lua_State *L, int n)
Definition: lapi.cpp:1125
cl_event event
Definition: glew.h:3070
LUALIB_API void luaL_checkany(lua_State *L, int narg)
Definition: lauxlib.cpp:353
LUALIB_API int luaL_execresult(lua_State *L, int stat)
Definition: lauxlib.cpp:249
static int skipBOM(LoadF *lf)
Definition: lauxlib.cpp:598
static int panic(lua_State *L)
Definition: lauxlib.cpp:932
static void pushfuncname(lua_State *L, lua_Debug *ar)
Definition: lauxlib.cpp:82
LUA_API int lua_checkstack(lua_State *L, int size)
Definition: lapi.cpp:86
#define c
Definition: glew.h:12743
LUALIB_API void luaL_unref(lua_State *L, int t, int ref)
Definition: lauxlib.cpp:545
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
Definition: lapi.cpp:536
static int typeerror(lua_State *L, int narg, const char *tname)
Definition: lauxlib.cpp:170
LUALIB_API void luaL_openlib(lua_State *L, const char *libname, const luaL_Reg *l, int nup)
Definition: lauxlib.cpp:829
char * b
Definition: lauxlib.h:144
int currentline
Definition: lua.h:404
#define e
LUALIB_API int luaL_len(lua_State *L, int idx)
Definition: lauxlib.cpp:727
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)
Definition: lapi.cpp:220
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
Definition: lauxlib.cpp:850
static int findfield(lua_State *L, int objidx, int level)
Definition: lauxlib.cpp:42
GLdouble s
Definition: glew.h:1358
LUALIB_API void luaL_pushmodule(lua_State *L, const char *modname, int sizehint)
Definition: lauxlib.cpp:812
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
Definition: lapi.cpp:477
#define luaL_optstring(L, n, d)
Definition: lauxlib.h:116
LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *tname)
Definition: lauxlib.cpp:176
struct LoadS LoadS
LUA_API void lua_rawget(lua_State *L, int idx)
Definition: lapi.cpp:633
LUA_NUMBER lua_Number
Definition: lua.h:102
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
Definition: lapi.cpp:507
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:752
#define LUA_TBOOLEAN
Definition: lua.h:78
LUA_API int lua_next(lua_State *L, int idx)
Definition: lapi.cpp:1108
#define LUA_REFNIL
Definition: lauxlib.h:70
LUA_API const char * lua_typename(lua_State *L, int t)
Definition: lapi.cpp:249
int linedefined
Definition: lua.h:405
#define LUALIB_API
Definition: luaconf.h:162
#define luaL_checkstring(L, n)
Definition: lauxlib.h:115