The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lapi.cpp
Go to the documentation of this file.
1 /*
2 ** Lua API
3 ** See Copyright Notice in lua.h
4 */
5 
6 
7 #include <stdarg.h>
8 #include <string.h>
9 
10 #define lapi_c
11 #define LUA_CORE
12 
13 #include "lua.h"
14 
15 #include "lapi.h"
16 #include "ldebug.h"
17 #include "ldo.h"
18 #include "lfunc.h"
19 #include "lgc.h"
20 #include "lmem.h"
21 #include "lobject.h"
22 #include "lstate.h"
23 #include "lstring.h"
24 #include "ltable.h"
25 #include "ltm.h"
26 #include "lundump.h"
27 #include "lvm.h"
28 
29 
30 
31 /* value at a non-valid index */
32 #define NONVALIDVALUE cast(TValue *, luaO_nilobject)
33 
34 /* corresponding test */
35 #define isvalid(o) ((o) != luaO_nilobject)
36 
37 /* test for pseudo index */
38 #define ispseudo(i) ((i) <= LUA_REGISTRYINDEX)
39 
40 /* test for valid but not pseudo index */
41 #define isstackindex(i, o) (isvalid(o) && !ispseudo(i))
42 
43 #define api_checkvalidindex(L, o) api_check(L, isvalid(o), "invalid index")
44 
45 #define api_checkstackindex(L, i, o) \
46  api_check(L, isstackindex(i, o), "index not in the stack")
47 
48 
49 static TValue *index2addr (lua_State *L, int idx) {
50  CallInfo *ci = L->ci;
51  if (idx > 0) {
52  TValue *o = ci->func + idx;
53  api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index");
54  if (o >= L->top) return NONVALIDVALUE;
55  else return o;
56  }
57  else if (!ispseudo(idx)) { /* negative index */
58  api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
59  return L->top + idx;
60  }
61  else if (idx == LUA_REGISTRYINDEX)
62  return &G(L)->l_registry;
63  else { /* upvalues */
64  idx = LUA_REGISTRYINDEX - idx;
65  api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
66  if (ttislcf(ci->func)) /* light C function? */
67  return NONVALIDVALUE; /* it has no upvalues */
68  else {
69  CClosure *func = clCvalue(ci->func);
70  return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;
71  }
72  }
73 }
74 
75 
76 /*
77 ** to be called by 'lua_checkstack' in protected mode, to grow stack
78 ** capturing memory errors
79 */
80 static void growstack (lua_State *L, void *ud) {
81  int size = *(int *)ud;
82  luaD_growstack(L, size);
83 }
84 
85 
87  int res;
88  CallInfo *ci = L->ci;
89  lua_lock(L);
90  if (L->stack_last - L->top > size) /* stack large enough? */
91  res = 1; /* yes; check is OK */
92  else { /* no; need to grow stack */
93  int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;
94  if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */
95  res = 0; /* no */
96  else /* try to grow stack */
97  res = (luaD_rawrunprotected(L, &growstack, &size) == LUA_OK);
98  }
99  if (res && ci->top < L->top + size)
100  ci->top = L->top + size; /* adjust frame top */
101  lua_unlock(L);
102  return res;
103 }
104 
105 
106 LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
107  int i;
108  if (from == to) return;
109  lua_lock(to);
110  api_checknelems(from, n);
111  api_check(from, G(from) == G(to), "moving among independent states");
112  api_check(from, to->ci->top - to->top >= n, "not enough elements to move");
113  from->top -= n;
114  for (i = 0; i < n; i++) {
115  setobj2s(to, to->top++, from->top + i);
116  }
117  lua_unlock(to);
118 }
119 
120 
122  lua_CFunction old;
123  lua_lock(L);
124  old = G(L)->panic;
125  G(L)->panic = panicf;
126  lua_unlock(L);
127  return old;
128 }
129 
130 
132  static const lua_Number version = LUA_VERSION_NUM;
133  if (L == NULL) return &version;
134  else return G(L)->version;
135 }
136 
137 
138 
139 /*
140 ** basic stack manipulation
141 */
142 
143 
144 /*
145 ** convert an acceptable stack index into an absolute index
146 */
147 LUA_API int lua_absindex (lua_State *L, int idx) {
148  return (idx > 0 || ispseudo(idx))
149  ? idx
150  : cast_int(L->top - L->ci->func + idx);
151 }
152 
153 
155  return cast_int(L->top - (L->ci->func + 1));
156 }
157 
158 
159 LUA_API void lua_settop (lua_State *L, int idx) {
160  StkId func = L->ci->func;
161  lua_lock(L);
162  if (idx >= 0) {
163  api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
164  while (L->top < (func + 1) + idx)
165  setnilvalue(L->top++);
166  L->top = (func + 1) + idx;
167  }
168  else {
169  api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
170  L->top += idx+1; /* `subtract' index (index is negative) */
171  }
172  lua_unlock(L);
173 }
174 
175 
176 LUA_API void lua_remove (lua_State *L, int idx) {
177  StkId p;
178  lua_lock(L);
179  p = index2addr(L, idx);
180  api_checkstackindex(L, idx, p);
181  while (++p < L->top) setobjs2s(L, p-1, p);
182  L->top--;
183  lua_unlock(L);
184 }
185 
186 
187 LUA_API void lua_insert (lua_State *L, int idx) {
188  StkId p;
189  StkId q;
190  lua_lock(L);
191  p = index2addr(L, idx);
192  api_checkstackindex(L, idx, p);
193  for (q = L->top; q > p; q--) /* use L->top as a temporary */
194  setobjs2s(L, q, q - 1);
195  setobjs2s(L, p, L->top);
196  lua_unlock(L);
197 }
198 
199 
200 static void moveto (lua_State *L, TValue *fr, int idx) {
201  TValue *to = index2addr(L, idx);
202  api_checkvalidindex(L, to);
203  setobj(L, to, fr);
204  if (idx < LUA_REGISTRYINDEX) /* function upvalue? */
205  luaC_barrier(L, clCvalue(L->ci->func), fr);
206  /* LUA_REGISTRYINDEX does not need gc barrier
207  (collector revisits it before finishing collection) */
208 }
209 
210 
211 LUA_API void lua_replace (lua_State *L, int idx) {
212  lua_lock(L);
213  api_checknelems(L, 1);
214  moveto(L, L->top - 1, idx);
215  L->top--;
216  lua_unlock(L);
217 }
218 
219 
220 LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {
221  TValue *fr;
222  lua_lock(L);
223  fr = index2addr(L, fromidx);
224  moveto(L, fr, toidx);
225  lua_unlock(L);
226 }
227 
228 
229 LUA_API void lua_pushvalue (lua_State *L, int idx) {
230  lua_lock(L);
231  setobj2s(L, L->top, index2addr(L, idx));
232  api_incr_top(L);
233  lua_unlock(L);
234 }
235 
236 
237 
238 /*
239 ** access functions (stack -> C)
240 */
241 
242 
243 LUA_API int lua_type (lua_State *L, int idx) {
244  StkId o = index2addr(L, idx);
245  return (isvalid(o) ? ttypenv(o) : LUA_TNONE);
246 }
247 
248 
249 LUA_API const char *lua_typename (lua_State *L, int t) {
250  UNUSED(L);
251  return ttypename(t);
252 }
253 
254 
255 LUA_API int lua_iscfunction (lua_State *L, int idx) {
256  StkId o = index2addr(L, idx);
257  return (ttislcf(o) || (ttisCclosure(o)));
258 }
259 
260 
261 LUA_API int lua_isnumber (lua_State *L, int idx) {
262  TValue n;
263  const TValue *o = index2addr(L, idx);
264  return tonumber(o, &n);
265 }
266 
267 
268 LUA_API int lua_isstring (lua_State *L, int idx) {
269  int t = lua_type(L, idx);
270  return (t == LUA_TSTRING || t == LUA_TNUMBER);
271 }
272 
273 
274 LUA_API int lua_isuserdata (lua_State *L, int idx) {
275  const TValue *o = index2addr(L, idx);
276  return (ttisuserdata(o) || ttislightuserdata(o));
277 }
278 
279 
280 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
281  StkId o1 = index2addr(L, index1);
282  StkId o2 = index2addr(L, index2);
283  return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;
284 }
285 
286 
287 LUA_API void lua_arith (lua_State *L, int op) {
288  StkId o1; /* 1st operand */
289  StkId o2; /* 2nd operand */
290  lua_lock(L);
291  if (op != LUA_OPUNM) /* all other operations expect two operands */
292  api_checknelems(L, 2);
293  else { /* for unary minus, add fake 2nd operand */
294  api_checknelems(L, 1);
295  setobjs2s(L, L->top, L->top - 1);
296  L->top++;
297  }
298  o1 = L->top - 2;
299  o2 = L->top - 1;
300  if (ttisnumber(o1) && ttisnumber(o2)) {
301  setnvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
302  }
303  else
304  luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD));
305  L->top--;
306  lua_unlock(L);
307 }
308 
309 
310 LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
311  StkId o1, o2;
312  int i = 0;
313  lua_lock(L); /* may call tag method */
314  o1 = index2addr(L, index1);
315  o2 = index2addr(L, index2);
316  if (isvalid(o1) && isvalid(o2)) {
317  switch (op) {
318  case LUA_OPEQ: i = equalobj(L, o1, o2); break;
319  case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
320  case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
321  default: api_check(L, 0, "invalid option");
322  }
323  }
324  lua_unlock(L);
325  return i;
326 }
327 
328 
329 LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) {
330  TValue n;
331  const TValue *o = index2addr(L, idx);
332  if (tonumber(o, &n)) {
333  if (isnum) *isnum = 1;
334  return nvalue(o);
335  }
336  else {
337  if (isnum) *isnum = 0;
338  return 0;
339  }
340 }
341 
342 
343 LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) {
344  TValue n;
345  const TValue *o = index2addr(L, idx);
346  if (tonumber(o, &n)) {
348  lua_Number num = nvalue(o);
349  lua_number2integer(res, num);
350  if (isnum) *isnum = 1;
351  return res;
352  }
353  else {
354  if (isnum) *isnum = 0;
355  return 0;
356  }
357 }
358 
359 
360 LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) {
361  TValue n;
362  const TValue *o = index2addr(L, idx);
363  if (tonumber(o, &n)) {
365  lua_Number num = nvalue(o);
366  lua_number2unsigned(res, num);
367  if (isnum) *isnum = 1;
368  return res;
369  }
370  else {
371  if (isnum) *isnum = 0;
372  return 0;
373  }
374 }
375 
376 
377 LUA_API int lua_toboolean (lua_State *L, int idx) {
378  const TValue *o = index2addr(L, idx);
379  return !l_isfalse(o);
380 }
381 
382 
383 LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
384  StkId o = index2addr(L, idx);
385  if (!ttisstring(o)) {
386  lua_lock(L); /* `luaV_tostring' may create a new string */
387  if (!luaV_tostring(L, o)) { /* conversion failed? */
388  if (len != NULL) *len = 0;
389  lua_unlock(L);
390  return NULL;
391  }
392  luaC_checkGC(L);
393  o = index2addr(L, idx); /* previous call may reallocate the stack */
394  lua_unlock(L);
395  }
396  if (len != NULL) *len = tsvalue(o)->len;
397  return svalue(o);
398 }
399 
400 
401 LUA_API size_t lua_rawlen (lua_State *L, int idx) {
402  StkId o = index2addr(L, idx);
403  switch (ttypenv(o)) {
404  case LUA_TSTRING: return tsvalue(o)->len;
405  case LUA_TUSERDATA: return uvalue(o)->len;
406  case LUA_TTABLE: return luaH_getn(hvalue(o));
407  default: return 0;
408  }
409 }
410 
411 
413  StkId o = index2addr(L, idx);
414  if (ttislcf(o)) return fvalue(o);
415  else if (ttisCclosure(o))
416  return clCvalue(o)->f;
417  else return NULL; /* not a C function */
418 }
419 
420 
421 LUA_API void *lua_touserdata (lua_State *L, int idx) {
422  StkId o = index2addr(L, idx);
423  switch (ttypenv(o)) {
424  case LUA_TUSERDATA: return (rawuvalue(o) + 1);
425  case LUA_TLIGHTUSERDATA: return pvalue(o);
426  default: return NULL;
427  }
428 }
429 
430 
432  StkId o = index2addr(L, idx);
433  return (!ttisthread(o)) ? NULL : thvalue(o);
434 }
435 
436 
437 LUA_API const void *lua_topointer (lua_State *L, int idx) {
438  StkId o = index2addr(L, idx);
439  switch (ttype(o)) {
440  case LUA_TTABLE: return hvalue(o);
441  case LUA_TLCL: return clLvalue(o);
442  case LUA_TCCL: return clCvalue(o);
443  case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
444  case LUA_TTHREAD: return thvalue(o);
445  case LUA_TUSERDATA:
446  case LUA_TLIGHTUSERDATA:
447  return lua_touserdata(L, idx);
448  default: return NULL;
449  }
450 }
451 
452 
453 
454 /*
455 ** push functions (C -> stack)
456 */
457 
458 
460  lua_lock(L);
461  setnilvalue(L->top);
462  api_incr_top(L);
463  lua_unlock(L);
464 }
465 
466 
468  lua_lock(L);
469  setnvalue(L->top, n);
470  luai_checknum(L, L->top,
471  luaG_runerror(L, "C API - attempt to push a signaling NaN"));
472  api_incr_top(L);
473  lua_unlock(L);
474 }
475 
476 
478  lua_lock(L);
479  setnvalue(L->top, cast_num(n));
480  api_incr_top(L);
481  lua_unlock(L);
482 }
483 
484 
486  lua_Number n;
487  lua_lock(L);
488  n = lua_unsigned2number(u);
489  setnvalue(L->top, n);
490  api_incr_top(L);
491  lua_unlock(L);
492 }
493 
494 
495 LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
496  TString *ts;
497  lua_lock(L);
498  luaC_checkGC(L);
499  ts = luaS_newlstr(L, s, len);
500  setsvalue2s(L, L->top, ts);
501  api_incr_top(L);
502  lua_unlock(L);
503  return getstr(ts);
504 }
505 
506 
507 LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
508  if (s == NULL) {
509  lua_pushnil(L);
510  return NULL;
511  }
512  else {
513  TString *ts;
514  lua_lock(L);
515  luaC_checkGC(L);
516  ts = luaS_new(L, s);
517  setsvalue2s(L, L->top, ts);
518  api_incr_top(L);
519  lua_unlock(L);
520  return getstr(ts);
521  }
522 }
523 
524 
525 LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
526  va_list argp) {
527  const char *ret;
528  lua_lock(L);
529  luaC_checkGC(L);
530  ret = luaO_pushvfstring(L, fmt, argp);
531  lua_unlock(L);
532  return ret;
533 }
534 
535 
536 LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
537  const char *ret;
538  va_list argp;
539  lua_lock(L);
540  luaC_checkGC(L);
541  va_start(argp, fmt);
542  ret = luaO_pushvfstring(L, fmt, argp);
543  va_end(argp);
544  lua_unlock(L);
545  return ret;
546 }
547 
548 
550  lua_lock(L);
551  if (n == 0) {
552  setfvalue(L->top, fn);
553  }
554  else {
555  Closure *cl;
556  api_checknelems(L, n);
557  api_check(L, n <= MAXUPVAL, "upvalue index too large");
558  luaC_checkGC(L);
559  cl = luaF_newCclosure(L, n);
560  cl->c.f = fn;
561  L->top -= n;
562  while (n--)
563  setobj2n(L, &cl->c.upvalue[n], L->top + n);
564  setclCvalue(L, L->top, cl);
565  }
566  api_incr_top(L);
567  lua_unlock(L);
568 }
569 
570 
572  lua_lock(L);
573  setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
574  api_incr_top(L);
575  lua_unlock(L);
576 }
577 
578 
580  lua_lock(L);
581  setpvalue(L->top, p);
582  api_incr_top(L);
583  lua_unlock(L);
584 }
585 
586 
588  lua_lock(L);
589  setthvalue(L, L->top, L);
590  api_incr_top(L);
591  lua_unlock(L);
592  return (G(L)->mainthread == L);
593 }
594 
595 
596 
597 /*
598 ** get functions (Lua -> stack)
599 */
600 
601 
602 LUA_API void lua_getglobal (lua_State *L, const char *var) {
603  Table *reg = hvalue(&G(L)->l_registry);
604  const TValue *gt; /* global table */
605  lua_lock(L);
606  gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
607  setsvalue2s(L, L->top++, luaS_new(L, var));
608  luaV_gettable(L, gt, L->top - 1, L->top - 1);
609  lua_unlock(L);
610 }
611 
612 
613 LUA_API void lua_gettable (lua_State *L, int idx) {
614  StkId t;
615  lua_lock(L);
616  t = index2addr(L, idx);
617  luaV_gettable(L, t, L->top - 1, L->top - 1);
618  lua_unlock(L);
619 }
620 
621 
622 LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
623  StkId t;
624  lua_lock(L);
625  t = index2addr(L, idx);
626  setsvalue2s(L, L->top, luaS_new(L, k));
627  api_incr_top(L);
628  luaV_gettable(L, t, L->top - 1, L->top - 1);
629  lua_unlock(L);
630 }
631 
632 
633 LUA_API void lua_rawget (lua_State *L, int idx) {
634  StkId t;
635  lua_lock(L);
636  t = index2addr(L, idx);
637  api_check(L, ttistable(t), "table expected");
638  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
639  lua_unlock(L);
640 }
641 
642 
643 LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
644  StkId t;
645  lua_lock(L);
646  t = index2addr(L, idx);
647  api_check(L, ttistable(t), "table expected");
648  setobj2s(L, L->top, luaH_getint(hvalue(t), n));
649  api_incr_top(L);
650  lua_unlock(L);
651 }
652 
653 
654 LUA_API void lua_rawgetp (lua_State *L, int idx, const void *p) {
655  StkId t;
656  TValue k;
657  lua_lock(L);
658  t = index2addr(L, idx);
659  api_check(L, ttistable(t), "table expected");
660  setpvalue(&k, cast(void *, p));
661  setobj2s(L, L->top, luaH_get(hvalue(t), &k));
662  api_incr_top(L);
663  lua_unlock(L);
664 }
665 
666 
667 LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
668  Table *t;
669  lua_lock(L);
670  luaC_checkGC(L);
671  t = luaH_new(L);
672  sethvalue(L, L->top, t);
673  api_incr_top(L);
674  if (narray > 0 || nrec > 0)
675  luaH_resize(L, t, narray, nrec);
676  lua_unlock(L);
677 }
678 
679 
680 LUA_API int lua_getmetatable (lua_State *L, int objindex) {
681  const TValue *obj;
682  Table *mt = NULL;
683  int res;
684  lua_lock(L);
685  obj = index2addr(L, objindex);
686  switch (ttypenv(obj)) {
687  case LUA_TTABLE:
688  mt = hvalue(obj)->metatable;
689  break;
690  case LUA_TUSERDATA:
691  mt = uvalue(obj)->metatable;
692  break;
693  default:
694  mt = G(L)->mt[ttypenv(obj)];
695  break;
696  }
697  if (mt == NULL)
698  res = 0;
699  else {
700  sethvalue(L, L->top, mt);
701  api_incr_top(L);
702  res = 1;
703  }
704  lua_unlock(L);
705  return res;
706 }
707 
708 
709 LUA_API void lua_getuservalue (lua_State *L, int idx) {
710  StkId o;
711  lua_lock(L);
712  o = index2addr(L, idx);
713  api_check(L, ttisuserdata(o), "userdata expected");
714  if (uvalue(o)->env) {
715  sethvalue(L, L->top, uvalue(o)->env);
716  } else
717  setnilvalue(L->top);
718  api_incr_top(L);
719  lua_unlock(L);
720 }
721 
722 
723 /*
724 ** set functions (stack -> Lua)
725 */
726 
727 
728 LUA_API void lua_setglobal (lua_State *L, const char *var) {
729  Table *reg = hvalue(&G(L)->l_registry);
730  const TValue *gt; /* global table */
731  lua_lock(L);
732  api_checknelems(L, 1);
733  gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
734  setsvalue2s(L, L->top++, luaS_new(L, var));
735  luaV_settable(L, gt, L->top - 1, L->top - 2);
736  L->top -= 2; /* pop value and key */
737  lua_unlock(L);
738 }
739 
740 
741 LUA_API void lua_settable (lua_State *L, int idx) {
742  StkId t;
743  lua_lock(L);
744  api_checknelems(L, 2);
745  t = index2addr(L, idx);
746  luaV_settable(L, t, L->top - 2, L->top - 1);
747  L->top -= 2; /* pop index and value */
748  lua_unlock(L);
749 }
750 
751 
752 LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
753  StkId t;
754  lua_lock(L);
755  api_checknelems(L, 1);
756  t = index2addr(L, idx);
757  setsvalue2s(L, L->top++, luaS_new(L, k));
758  luaV_settable(L, t, L->top - 1, L->top - 2);
759  L->top -= 2; /* pop value and key */
760  lua_unlock(L);
761 }
762 
763 
764 LUA_API void lua_rawset (lua_State *L, int idx) {
765  StkId t;
766  lua_lock(L);
767  api_checknelems(L, 2);
768  t = index2addr(L, idx);
769  api_check(L, ttistable(t), "table expected");
770  setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
772  luaC_barrierback(L, gcvalue(t), L->top-1);
773  L->top -= 2;
774  lua_unlock(L);
775 }
776 
777 
778 LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
779  StkId t;
780  lua_lock(L);
781  api_checknelems(L, 1);
782  t = index2addr(L, idx);
783  api_check(L, ttistable(t), "table expected");
784  luaH_setint(L, hvalue(t), n, L->top - 1);
785  luaC_barrierback(L, gcvalue(t), L->top-1);
786  L->top--;
787  lua_unlock(L);
788 }
789 
790 
791 LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
792  StkId t;
793  TValue k;
794  lua_lock(L);
795  api_checknelems(L, 1);
796  t = index2addr(L, idx);
797  api_check(L, ttistable(t), "table expected");
798  setpvalue(&k, cast(void *, p));
799  setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1);
800  luaC_barrierback(L, gcvalue(t), L->top - 1);
801  L->top--;
802  lua_unlock(L);
803 }
804 
805 
806 LUA_API int lua_setmetatable (lua_State *L, int objindex) {
807  TValue *obj;
808  Table *mt;
809  lua_lock(L);
810  api_checknelems(L, 1);
811  obj = index2addr(L, objindex);
812  if (ttisnil(L->top - 1))
813  mt = NULL;
814  else {
815  api_check(L, ttistable(L->top - 1), "table expected");
816  mt = hvalue(L->top - 1);
817  }
818  switch (ttypenv(obj)) {
819  case LUA_TTABLE: {
820  hvalue(obj)->metatable = mt;
821  if (mt) {
822  luaC_objbarrierback(L, gcvalue(obj), mt);
823  luaC_checkfinalizer(L, gcvalue(obj), mt);
824  }
825  break;
826  }
827  case LUA_TUSERDATA: {
828  uvalue(obj)->metatable = mt;
829  if (mt) {
830  luaC_objbarrier(L, rawuvalue(obj), mt);
831  luaC_checkfinalizer(L, gcvalue(obj), mt);
832  }
833  break;
834  }
835  default: {
836  G(L)->mt[ttypenv(obj)] = mt;
837  break;
838  }
839  }
840  L->top--;
841  lua_unlock(L);
842  return 1;
843 }
844 
845 
846 LUA_API void lua_setuservalue (lua_State *L, int idx) {
847  StkId o;
848  lua_lock(L);
849  api_checknelems(L, 1);
850  o = index2addr(L, idx);
851  api_check(L, ttisuserdata(o), "userdata expected");
852  if (ttisnil(L->top - 1))
853  uvalue(o)->env = NULL;
854  else {
855  api_check(L, ttistable(L->top - 1), "table expected");
856  uvalue(o)->env = hvalue(L->top - 1);
857  luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
858  }
859  L->top--;
860  lua_unlock(L);
861 }
862 
863 
864 /*
865 ** `load' and `call' functions (run Lua code)
866 */
867 
868 
869 #define checkresults(L,na,nr) \
870  api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
871  "results from function overflow current stack size")
872 
873 
874 LUA_API int lua_getctx (lua_State *L, int *ctx) {
875  if (L->ci->callstatus & CIST_YIELDED) {
876  if (ctx) *ctx = L->ci->u.c.ctx;
877  return L->ci->u.c.status;
878  }
879  else return LUA_OK;
880 }
881 
882 
883 LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx,
884  lua_CFunction k) {
885  StkId func;
886  lua_lock(L);
887  api_check(L, k == NULL || !isLua(L->ci),
888  "cannot use continuations inside hooks");
889  api_checknelems(L, nargs+1);
890  api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
891  checkresults(L, nargs, nresults);
892  func = L->top - (nargs+1);
893  if (k != NULL && L->nny == 0) { /* need to prepare continuation? */
894  L->ci->u.c.k = k; /* save continuation */
895  L->ci->u.c.ctx = ctx; /* save context */
896  luaD_call(L, func, nresults, 1); /* do the call */
897  }
898  else /* no continuation or no yieldable */
899  luaD_call(L, func, nresults, 0); /* just do the call */
900  adjustresults(L, nresults);
901  lua_unlock(L);
902 }
903 
904 
905 
906 /*
907 ** Execute a protected call.
908 */
909 struct CallS { /* data to `f_call' */
911  int nresults;
912 };
913 
914 
915 static void f_call (lua_State *L, void *ud) {
916  struct CallS *c = cast(struct CallS *, ud);
917  luaD_call(L, c->func, c->nresults, 0);
918 }
919 
920 
921 
922 LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
923  int ctx, lua_CFunction k) {
924  struct CallS c;
925  int status;
926  ptrdiff_t func;
927  lua_lock(L);
928  api_check(L, k == NULL || !isLua(L->ci),
929  "cannot use continuations inside hooks");
930  api_checknelems(L, nargs+1);
931  api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
932  checkresults(L, nargs, nresults);
933  if (errfunc == 0)
934  func = 0;
935  else {
936  StkId o = index2addr(L, errfunc);
937  api_checkstackindex(L, errfunc, o);
938  func = savestack(L, o);
939  }
940  c.func = L->top - (nargs+1); /* function to be called */
941  if (k == NULL || L->nny > 0) { /* no continuation or no yieldable? */
942  c.nresults = nresults; /* do a 'conventional' protected call */
943  status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
944  }
945  else { /* prepare continuation (call is already protected by 'resume') */
946  CallInfo *ci = L->ci;
947  ci->u.c.k = k; /* save continuation */
948  ci->u.c.ctx = ctx; /* save context */
949  /* save information for error recovery */
950  ci->extra = savestack(L, c.func);
951  ci->u.c.old_allowhook = L->allowhook;
952  ci->u.c.old_errfunc = L->errfunc;
953  L->errfunc = func;
954  /* mark that function may do error recovery */
955  ci->callstatus |= CIST_YPCALL;
956  luaD_call(L, c.func, nresults, 1); /* do the call */
957  ci->callstatus &= ~CIST_YPCALL;
958  L->errfunc = ci->u.c.old_errfunc;
959  status = LUA_OK; /* if it is here, there were no errors */
960  }
961  adjustresults(L, nresults);
962  lua_unlock(L);
963  return status;
964 }
965 
966 
968  const char *chunkname, const char *mode) {
969  ZIO z;
970  int status;
971  lua_lock(L);
972  if (!chunkname) chunkname = "?";
973  luaZ_init(L, &z, reader, data);
974  status = luaD_protectedparser(L, &z, chunkname, mode);
975  if (status == LUA_OK) { /* no errors? */
976  LClosure *f = clLvalue(L->top - 1); /* get newly created function */
977  if (f->nupvalues == 1) { /* does it have one upvalue? */
978  /* get global table from registry */
979  Table *reg = hvalue(&G(L)->l_registry);
980  const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
981  /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
982  setobj(L, f->upvals[0]->v, gt);
983  luaC_barrier(L, f->upvals[0], gt);
984  }
985  }
986  lua_unlock(L);
987  return status;
988 }
989 
990 
992  int status;
993  TValue *o;
994  lua_lock(L);
995  api_checknelems(L, 1);
996  o = L->top - 1;
997  if (isLfunction(o))
998  status = luaU_dump(L, getproto(o), writer, data, 0);
999  else
1000  status = 1;
1001  lua_unlock(L);
1002  return status;
1003 }
1004 
1005 
1007  return L->status;
1008 }
1009 
1010 
1011 /*
1012 ** Garbage-collection function
1013 */
1014 
1015 LUA_API int lua_gc (lua_State *L, int what, int data) {
1016  int res = 0;
1017  global_State *g;
1018  lua_lock(L);
1019  g = G(L);
1020  switch (what) {
1021  case LUA_GCSTOP: {
1022  g->gcrunning = 0;
1023  break;
1024  }
1025  case LUA_GCRESTART: {
1026  luaE_setdebt(g, 0);
1027  g->gcrunning = 1;
1028  break;
1029  }
1030  case LUA_GCCOLLECT: {
1031  luaC_fullgc(L, 0);
1032  break;
1033  }
1034  case LUA_GCCOUNT: {
1035  /* GC values are expressed in Kbytes: #bytes/2^10 */
1036  res = cast_int(gettotalbytes(g) >> 10);
1037  break;
1038  }
1039  case LUA_GCCOUNTB: {
1040  res = cast_int(gettotalbytes(g) & 0x3ff);
1041  break;
1042  }
1043  case LUA_GCSTEP: {
1044  if (g->gckind == KGC_GEN) { /* generational mode? */
1045  res = (g->GCestimate == 0); /* true if it will do major collection */
1046  luaC_forcestep(L); /* do a single step */
1047  }
1048  else {
1049  lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE;
1050  if (g->gcrunning)
1051  debt += g->GCdebt; /* include current debt */
1052  luaE_setdebt(g, debt);
1053  luaC_forcestep(L);
1054  if (g->gcstate == GCSpause) /* end of cycle? */
1055  res = 1; /* signal it */
1056  }
1057  break;
1058  }
1059  case LUA_GCSETPAUSE: {
1060  res = g->gcpause;
1061  g->gcpause = data;
1062  break;
1063  }
1064  case LUA_GCSETMAJORINC: {
1065  res = g->gcmajorinc;
1066  g->gcmajorinc = data;
1067  break;
1068  }
1069  case LUA_GCSETSTEPMUL: {
1070  res = g->gcstepmul;
1071  g->gcstepmul = data;
1072  break;
1073  }
1074  case LUA_GCISRUNNING: {
1075  res = g->gcrunning;
1076  break;
1077  }
1078  case LUA_GCGEN: { /* change collector to generational mode */
1080  break;
1081  }
1082  case LUA_GCINC: { /* change collector to incremental mode */
1084  break;
1085  }
1086  default: res = -1; /* invalid option */
1087  }
1088  lua_unlock(L);
1089  return res;
1090 }
1091 
1092 
1093 
1094 /*
1095 ** miscellaneous functions
1096 */
1097 
1098 
1100  lua_lock(L);
1101  api_checknelems(L, 1);
1102  luaG_errormsg(L);
1103  /* code unreachable; will unlock when control actually leaves the kernel */
1104  return 0; /* to avoid warnings */
1105 }
1106 
1107 
1108 LUA_API int lua_next (lua_State *L, int idx) {
1109  StkId t;
1110  int more;
1111  lua_lock(L);
1112  t = index2addr(L, idx);
1113  api_check(L, ttistable(t), "table expected");
1114  more = luaH_next(L, hvalue(t), L->top - 1);
1115  if (more) {
1116  api_incr_top(L);
1117  }
1118  else /* no more elements */
1119  L->top -= 1; /* remove key */
1120  lua_unlock(L);
1121  return more;
1122 }
1123 
1124 
1125 LUA_API void lua_concat (lua_State *L, int n) {
1126  lua_lock(L);
1127  api_checknelems(L, n);
1128  if (n >= 2) {
1129  luaC_checkGC(L);
1130  luaV_concat(L, n);
1131  }
1132  else if (n == 0) { /* push empty string */
1133  setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
1134  api_incr_top(L);
1135  }
1136  /* else n == 1; nothing to do */
1137  lua_unlock(L);
1138 }
1139 
1140 
1141 LUA_API void lua_len (lua_State *L, int idx) {
1142  StkId t;
1143  lua_lock(L);
1144  t = index2addr(L, idx);
1145  luaV_objlen(L, L->top, t);
1146  api_incr_top(L);
1147  lua_unlock(L);
1148 }
1149 
1150 
1152  lua_Alloc f;
1153  lua_lock(L);
1154  if (ud) *ud = G(L)->ud;
1155  f = G(L)->frealloc;
1156  lua_unlock(L);
1157  return f;
1158 }
1159 
1160 
1162  lua_lock(L);
1163  G(L)->ud = ud;
1164  G(L)->frealloc = f;
1165  lua_unlock(L);
1166 }
1167 
1168 
1170  Udata *u;
1171  lua_lock(L);
1172  luaC_checkGC(L);
1173  u = luaS_newudata(L, size, NULL);
1174  setuvalue(L, L->top, u);
1175  api_incr_top(L);
1176  lua_unlock(L);
1177  return u + 1;
1178 }
1179 
1180 
1181 
1182 static const char *aux_upvalue (StkId fi, int n, TValue **val,
1183  GCObject **owner) {
1184  switch (ttype(fi)) {
1185  case LUA_TCCL: { /* C closure */
1186  CClosure *f = clCvalue(fi);
1187  if (!(1 <= n && n <= f->nupvalues)) return NULL;
1188  *val = &f->upvalue[n-1];
1189  if (owner) *owner = obj2gco(f);
1190  return "";
1191  }
1192  case LUA_TLCL: { /* Lua closure */
1193  LClosure *f = clLvalue(fi);
1194  TString *name;
1195  Proto *p = f->p;
1196  if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
1197  *val = f->upvals[n-1]->v;
1198  if (owner) *owner = obj2gco(f->upvals[n - 1]);
1199  name = p->upvalues[n-1].name;
1200  return (name == NULL) ? "" : getstr(name);
1201  }
1202  default: return NULL; /* not a closure */
1203  }
1204 }
1205 
1206 
1207 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
1208  const char *name;
1209  TValue *val = NULL; /* to avoid warnings */
1210  lua_lock(L);
1211  name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL);
1212  if (name) {
1213  setobj2s(L, L->top, val);
1214  api_incr_top(L);
1215  }
1216  lua_unlock(L);
1217  return name;
1218 }
1219 
1220 
1221 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
1222  const char *name;
1223  TValue *val = NULL; /* to avoid warnings */
1224  GCObject *owner = NULL; /* to avoid warnings */
1225  StkId fi;
1226  lua_lock(L);
1227  fi = index2addr(L, funcindex);
1228  api_checknelems(L, 1);
1229  name = aux_upvalue(fi, n, &val, &owner);
1230  if (name) {
1231  L->top--;
1232  setobj(L, val, L->top);
1233  luaC_barrier(L, owner, L->top);
1234  }
1235  lua_unlock(L);
1236  return name;
1237 }
1238 
1239 
1240 static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {
1241  LClosure *f;
1242  StkId fi = index2addr(L, fidx);
1243  api_check(L, ttisLclosure(fi), "Lua function expected");
1244  f = clLvalue(fi);
1245  api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
1246  if (pf) *pf = f;
1247  return &f->upvals[n - 1]; /* get its upvalue pointer */
1248 }
1249 
1250 
1251 LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {
1252  StkId fi = index2addr(L, fidx);
1253  switch (ttype(fi)) {
1254  case LUA_TLCL: { /* lua closure */
1255  return *getupvalref(L, fidx, n, NULL);
1256  }
1257  case LUA_TCCL: { /* C closure */
1258  CClosure *f = clCvalue(fi);
1259  api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
1260  return &f->upvalue[n - 1];
1261  }
1262  default: {
1263  api_check(L, 0, "closure expected");
1264  return NULL;
1265  }
1266  }
1267 }
1268 
1269 
1270 LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
1271  int fidx2, int n2) {
1272  LClosure *f1;
1273  UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
1274  UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
1275  *up1 = *up2;
1276  luaC_objbarrier(L, f1, *up2);
1277 }
1278 
lu_byte allowhook
Definition: lstate.h:166
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
Definition: lapi.cpp:643
const char * luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)
Definition: lobject.cpp:178
#define LUA_TCCL
Definition: lobject.h:51
void luaE_setdebt(global_State *g, l_mem debt)
Definition: lstate.cpp:105
lua_Number luaO_arith(int op, lua_Number v1, lua_Number v2)
Definition: lobject.cpp:72
void luaV_concat(lua_State *L, int total)
Definition: lvm.cpp:293
LUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud)
Definition: lapi.cpp:1151
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
Definition: lapi.cpp:579
LUA_API void lua_setallocf(lua_State *L, lua_Alloc f, void *ud)
Definition: lapi.cpp:1161
#define LUA_TTHREAD
Definition: lua.h:85
l_mem GCdebt
Definition: lstate.h:115
GLdouble GLdouble z
Definition: glew.h:1527
ptrdiff_t errfunc
Definition: lstate.h:173
l_noret luaG_runerror(lua_State *L, const char *fmt,...)
Definition: ldebug.cpp:585
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
Definition: lapi.cpp:667
#define setuvalue(L, obj, x)
Definition: lobject.h:210
#define nvalue(o)
Definition: lobject.h:152
#define ttistable(o)
Definition: lobject.h:139
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:622
LUA_API void lua_replace(lua_State *L, int idx)
Definition: lapi.cpp:211
static UpVal ** getupvalref(lua_State *L, int fidx, int n, LClosure **pf)
Definition: lapi.cpp:1240
#define cast_num(i)
Definition: llimits.h:95
#define LUA_GCSETSTEPMUL
Definition: lua.h:287
lua_CFunction f
Definition: lobject.h:517
int luaH_next(lua_State *L, Table *t, StkId key)
Definition: ltable.cpp:168
#define gcvalue(o)
Definition: lobject.h:153
int luaH_getn(Table *t)
Definition: ltable.cpp:559
#define thvalue(o)
Definition: lobject.h:165
#define lua_number2integer(i, n)
Definition: llimits.h:240
#define equalobj(L, o1, o2)
Definition: lvm.h:19
void luaC_checkfinalizer(lua_State *L, GCObject *o, Table *mt)
Definition: lgc.cpp:872
Definition: lobject.h:559
LUA_API void lua_settop(lua_State *L, int idx)
Definition: lapi.cpp:159
#define obj2gco(v)
Definition: lstate.h:214
LUA_API int lua_type(lua_State *L, int idx)
Definition: lapi.cpp:243
static TValue * index2addr(lua_State *L, int idx)
Definition: lapi.cpp:49
void luaH_resize(lua_State *L, Table *t, int nasize, int nhsize)
Definition: ltable.cpp:303
#define setbvalue(obj, x)
Definition: lobject.h:197
#define LUA_TUSERDATA
Definition: lua.h:84
#define LUA_TLCF
Definition: lobject.h:50
void *(* lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize)
Definition: lua.h:69
StkId stack
Definition: lstate.h:161
#define isLfunction(o)
Definition: lobject.h:535
Definition: lobject.h:466
const GLfloat * c
Definition: glew.h:12741
LUA_API void lua_pushboolean(lua_State *L, int b)
Definition: lapi.cpp:571
LUA_API void lua_pushunsigned(lua_State *L, lua_Unsigned u)
Definition: lapi.cpp:485
#define setobjs2s
Definition: lobject.h:250
#define ttisstring(o)
Definition: lobject.h:136
#define CIST_YPCALL
Definition: lstate.h:99
Definition: lobject.h:430
#define fvalue(o)
Definition: lobject.h:162
#define GCSpause
Definition: lgc.h:43
int gcmajorinc
Definition: lstate.h:139
static void f_call(lua_State *L, void *ud)
Definition: lapi.cpp:915
#define api_checkstackindex(L, i, o)
Definition: lapi.cpp:45
#define invalidateTMcache(t)
Definition: ltable.h:17
int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
Definition: ldump.cpp:161
#define getproto(o)
Definition: lobject.h:537
CClosure c
Definition: lobject.h:530
#define LUA_OPUNM
Definition: lua.h:189
LUA_API void lua_getglobal(lua_State *L, const char *var)
Definition: lapi.cpp:602
#define LUA_GCSTEP
Definition: lua.h:285
LUA_API int lua_gettop(lua_State *L)
Definition: lapi.cpp:154
#define LUA_TLCL
Definition: lobject.h:49
LUA_API void lua_setuservalue(lua_State *L, int idx)
Definition: lapi.cpp:846
LUA_API const lua_Number * lua_version(lua_State *L)
Definition: lapi.cpp:131
#define ttislightuserdata(o)
Definition: lobject.h:135
const TValue * luaH_get(Table *t, const TValue *key)
Definition: ltable.cpp:480
StkId top
Definition: lstate.h:70
void luaC_forcestep(lua_State *L)
Definition: lgc.cpp:1162
#define setnvalue(obj, x)
Definition: lobject.h:186
#define cast(t, exp)
Definition: llimits.h:92
LUA_API void lua_settable(lua_State *L, int idx)
Definition: lapi.cpp:741
const char *(* lua_Reader)(lua_State *L, void *ud, size_t *sz)
Definition: lua.h:61
GLuint const GLfloat * val
Definition: glew.h:2614
#define ttisLclosure(o)
Definition: lobject.h:143
#define ttisnil(o)
Definition: lobject.h:133
LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)
Definition: lapi.cpp:412
#define setnilvalue(obj)
Definition: lobject.h:189
#define LUA_TLIGHTUSERDATA
Definition: lua.h:79
void luaV_objlen(lua_State *L, StkId ra, const TValue *rb)
Definition: lvm.cpp:335
#define api_checkvalidindex(L, o)
Definition: lapi.cpp:43
#define G(L)
Definition: lstate.h:178
const char * what() const
#define lua_unlock(L)
Definition: llimits.h:155
LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data)
Definition: lapi.cpp:991
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
Definition: ltable.cpp:509
LUA_API int lua_isuserdata(lua_State *L, int idx)
Definition: lapi.cpp:274
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
Definition: lapi.cpp:549
#define clCvalue(o)
Definition: lobject.h:161
#define setobj2s
Definition: lobject.h:252
lu_byte callstatus
Definition: lstate.h:73
void luaV_arith(lua_State *L, StkId ra, const TValue *rb, const TValue *rc, TMS op)
Definition: lvm.cpp:360
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
GLenum mode
Definition: glew.h:2390
#define pvalue(o)
Definition: lobject.h:154
#define luaC_barrier(L, p, v)
Definition: lgc.h:126
#define setfvalue(obj, x)
Definition: lobject.h:191
GLdouble GLdouble t
Definition: glew.h:1366
#define uvalue(o)
Definition: lobject.h:158
void luaV_gettable(lua_State *L, const TValue *t, TValue *key, StkId val)
Definition: lvm.cpp:109
LUA_API int lua_absindex(lua_State *L, int idx)
Definition: lapi.cpp:147
UpVal * upvals[1]
Definition: lobject.h:525
#define LUAI_MAXSTACK
Definition: luaconf.h:369
l_noret luaG_errormsg(lua_State *L)
Definition: ldebug.cpp:572
LUA_API void * lua_newuserdata(lua_State *L, size_t size)
Definition: lapi.cpp:1169
#define GCSTEPSIZE
Definition: lgc.h:31
LUA_API void lua_callk(lua_State *L, int nargs, int nresults, int ctx, lua_CFunction k)
Definition: lapi.cpp:883
TString * luaS_new(lua_State *L, const char *str)
Definition: lstring.cpp:169
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:55
#define KGC_GEN
Definition: lstate.h:55
Upvaldesc * upvalues
Definition: lobject.h:473
#define LUA_OPLT
Definition: lua.h:194
StkId top
Definition: lstate.h:156
LUA_API int lua_gc(lua_State *L, int what, int data)
Definition: lapi.cpp:1015
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
lu_byte gckind
Definition: lstate.h:123
#define LUA_GCSTOP
Definition: lua.h:280
GLdouble GLdouble GLdouble GLdouble q
Definition: glew.h:1382
StkId stack_last
Definition: lstate.h:160
#define sethvalue(L, obj, x)
Definition: lobject.h:230
#define ttypenv(o)
Definition: lobject.h:126
#define lua_lock(L)
Definition: llimits.h:154
#define gettotalbytes(g)
Definition: lstate.h:218
LUA_INTEGER lua_Integer
Definition: lua.h:106
#define LUA_TSTRING
Definition: lua.h:81
LUA_API int lua_compare(lua_State *L, int index1, int index2, int op)
Definition: lapi.cpp:310
LUA_API void lua_rawgetp(lua_State *L, int idx, const void *p)
Definition: lapi.cpp:654
#define getstr(ts)
Definition: lobject.h:421
#define LUA_GCSETMAJORINC
Definition: lua.h:288
LUA_API void lua_setglobal(lua_State *L, const char *var)
Definition: lapi.cpp:728
#define LUA_OPADD
Definition: lua.h:183
Definition: lobject.h:495
#define LUA_GCISRUNNING
Definition: lua.h:289
#define tonumber(o, n)
Definition: lvm.h:17
void luaC_changemode(lua_State *L, int mode)
Definition: lgc.cpp:951
struct CallInfo::@16::@18 c
#define LUA_TNONE
Definition: lua.h:75
TValue * v
Definition: lobject.h:497
LUA_API int lua_isstring(lua_State *L, int idx)
Definition: lapi.cpp:268
#define luaV_rawequalobj(o1, o2)
Definition: lvm.h:21
LUA_API int lua_rawequal(lua_State *L, int index1, int index2)
Definition: lapi.cpp:280
unsigned short nny
Definition: lstate.h:163
int luaD_pcall(lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef)
Definition: ldo.cpp:617
LUA_API lua_Unsigned lua_tounsignedx(lua_State *L, int idx, int *isnum)
Definition: lapi.cpp:360
Definition: ltm.h:24
Udata * luaS_newudata(lua_State *L, size_t s, Table *e)
Definition: lstring.cpp:174
LUAI_UMEM lu_mem
Definition: llimits.h:19
CallInfo * ci
Definition: lstate.h:158
LUA_API int lua_toboolean(lua_State *L, int idx)
Definition: lapi.cpp:377
void luaZ_init(lua_State *L, ZIO *z, lua_Reader reader, void *data)
Definition: lzio.cpp:35
GLenum GLsizei len
Definition: glew.h:5662
Definition: lapi.cpp:909
LUA_API void lua_upvaluejoin(lua_State *L, int fidx1, int n1, int fidx2, int n2)
Definition: lapi.cpp:1270
#define ttisthread(o)
Definition: lobject.h:146
LUA_API lua_State * lua_tothread(lua_State *L, int idx)
Definition: lapi.cpp:431
#define api_incr_top(L)
Definition: lapi.h:13
#define clLvalue(o)
Definition: lobject.h:160
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
union CallInfo::@16 u
GLuint num
Definition: glew.h:2552
LUA_API int lua_getmetatable(lua_State *L, int objindex)
Definition: lapi.cpp:680
GLhandleARB obj
Definition: glew.h:4486
LUA_API void * lua_upvalueid(lua_State *L, int fidx, int n)
Definition: lapi.cpp:1251
LUA_API int lua_setmetatable(lua_State *L, int objindex)
Definition: lapi.cpp:806
void luaD_growstack(lua_State *L, int n)
Definition: ldo.cpp:197
int luaD_protectedparser(lua_State *L, ZIO *z, const char *name, const char *mode)
Definition: ldo.cpp:684
#define LUA_API
Definition: luaconf.h:156
StkId func
Definition: lstate.h:69
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
LUA_API int lua_status(lua_State *L)
Definition: lapi.cpp:1006
int luaV_lessequal(lua_State *L, const TValue *l, const TValue *r)
Definition: lvm.cpp:243
GLfloat GLfloat p
Definition: glew.h:12766
#define ispseudo(i)
Definition: lapi.cpp:38
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum)
Definition: lapi.cpp:329
static void growstack(lua_State *L, void *ud)
Definition: lapi.cpp:80
Closure * luaF_newCclosure(lua_State *L, int n)
Definition: lfunc.cpp:22
LUA_API void lua_pushnil(lua_State *L)
Definition: lapi.cpp:459
StkId func
Definition: lapi.cpp:910
LUA_API const char * lua_setupvalue(lua_State *L, int funcindex, int n)
Definition: lapi.cpp:1221
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
Definition: lapi.cpp:467
LUA_API void lua_len(lua_State *L, int idx)
Definition: lapi.cpp:1141
#define ttisuserdata(o)
Definition: lobject.h:145
LUA_API int lua_pushthread(lua_State *L)
Definition: lapi.cpp:587
Table * luaH_new(lua_State *L)
Definition: ltable.cpp:367
LUA_API void lua_getuservalue(lua_State *L, int idx)
Definition: lapi.cpp:709
#define api_checknelems(L, n)
Definition: lapi.h:19
#define UNUSED(x)
Definition: global.hpp:56
GLuint res
Definition: glew.h:9258
LUA_API void * lua_touserdata(lua_State *L, int idx)
Definition: lapi.cpp:421
#define tsvalue(o)
Definition: lobject.h:156
#define setobj2t
Definition: lobject.h:259
Definition: lzio.h:53
LUA_API void lua_xmove(lua_State *from, lua_State *to, int n)
Definition: lapi.cpp:106
const TValue * luaH_getint(Table *t, int key)
Definition: ltable.cpp:445
LUA_API int lua_pcallk(lua_State *L, int nargs, int nresults, int errfunc, int ctx, lua_CFunction k)
Definition: lapi.cpp:922
int(* lua_Writer)(lua_State *L, const void *p, size_t sz, void *ud)
Definition: lua.h:63
int luaV_lessthan(lua_State *L, const TValue *l, const TValue *r)
Definition: lvm.cpp:231
LUA_API void lua_rawset(lua_State *L, int idx)
Definition: lapi.cpp:764
#define luai_checknum(L, o, c)
Definition: lobject.h:266
#define LUA_OPLE
Definition: lua.h:195
#define CIST_YIELDED
Definition: lstate.h:98
#define setpvalue(obj, x)
Definition: lobject.h:194
#define ttypename(x)
Definition: ltm.h:45
#define setobj(L, obj1, obj2)
Definition: lobject.h:239
#define LUA_GCCOLLECT
Definition: lua.h:282
#define LUA_GCCOUNT
Definition: lua.h:283
#define LUA_GCINC
Definition: lua.h:291
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname, const char *mode)
Definition: lapi.cpp:967
#define isvalid(o)
Definition: lapi.cpp:35
size_t i
Definition: function.cpp:1057
#define setclCvalue(L, obj, x)
Definition: lobject.h:225
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
Definition: lapi.cpp:778
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)
Definition: ltable.cpp:517
LUA_API void lua_rawsetp(lua_State *L, int idx, const void *p)
Definition: lapi.cpp:791
#define LUA_RIDX_GLOBALS
Definition: lua.h:97
int nresults
Definition: lapi.cpp:911
LUA_API int lua_iscfunction(lua_State *L, int idx)
Definition: lapi.cpp:255
static int writer(lua_State *L, const void *b, size_t size, void *B)
Definition: lstrlib.cpp:166
#define KGC_NORMAL
Definition: lstate.h:53
LUA_API void lua_insert(lua_State *L, int idx)
Definition: lapi.cpp:187
#define rawuvalue(o)
Definition: lobject.h:157
LUA_API void lua_pushvalue(lua_State *L, int idx)
Definition: lapi.cpp:229
#define ttislcf(o)
Definition: lobject.h:144
LUA_API const char * lua_pushvfstring(lua_State *L, const char *fmt, va_list argp)
Definition: lapi.cpp:525
#define luaC_barrierback(L, p, v)
Definition: lgc.h:129
LUA_API int lua_isnumber(lua_State *L, int idx)
Definition: lapi.cpp:261
static const char * aux_upvalue(StkId fi, int n, TValue **val, GCObject **owner)
Definition: lapi.cpp:1182
LUA_UNSIGNED lua_Unsigned
Definition: lua.h:109
static const char * reader(lua_State *L, void *ud, size_t *size)
Definition: luac.cpp:118
int gcpause
Definition: lstate.h:138
int luaD_rawrunprotected(lua_State *L, Pfunc f, void *ud)
Definition: ldo.cpp:147
TValue upvalue[1]
Definition: lobject.h:518
GLuint const GLchar * name
Definition: glew.h:1782
#define savestack(L, p)
Definition: ldo.h:21
LUA_API void lua_gettable(lua_State *L, int idx)
Definition: lapi.cpp:613
#define ttisnumber(o)
Definition: lobject.h:132
LUA_API size_t lua_rawlen(lua_State *L, int idx)
Definition: lapi.cpp:401
GLsizeiptr size
Definition: glew.h:1649
#define LUA_GCGEN
Definition: lua.h:290
LUA_API const char * lua_getupvalue(lua_State *L, int funcindex, int n)
Definition: lapi.cpp:1207
#define LUA_GCSETPAUSE
Definition: lua.h:286
#define lua_unsigned2number(u)
Definition: llimits.h:272
TMS
Definition: ltm.h:17
#define LUA_REGISTRYINDEX
Definition: lua.h:39
LUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf)
Definition: lapi.cpp:121
#define ttype(o)
Definition: lobject.h:123
#define NONVALIDVALUE
Definition: lapi.cpp:32
GLclampd n
Definition: glew.h:5903
LUA_API int lua_error(lua_State *L)
Definition: lapi.cpp:1099
LUA_API const void * lua_topointer(lua_State *L, int idx)
Definition: lapi.cpp:437
#define api_check(l, e, msg)
Definition: llimits.h:84
#define LUA_GCCOUNTB
Definition: lua.h:284
#define LUA_OK
Definition: lua.h:44
#define g
Definition: glew.h:12730
LUA_API void lua_concat(lua_State *L, int n)
Definition: lapi.cpp:1125
lu_byte gcstate
Definition: lstate.h:122
#define cast_int(i)
Definition: llimits.h:96
#define luaC_checkGC(L)
Definition: lgc.h:123
TString * name
Definition: lobject.h:446
#define luaC_objbarrierback(L, p, o)
Definition: lgc.h:136
struct Proto * p
Definition: lobject.h:524
int luaV_tostring(lua_State *L, StkId obj)
Definition: lvm.cpp:46
void luaD_call(lua_State *L, StkId func, int nResults, int allowyield)
Definition: ldo.cpp:415
LUA_API int lua_checkstack(lua_State *L, int size)
Definition: lapi.cpp:86
#define svalue(o)
Definition: lobject.h:424
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
Definition: lapi.cpp:536
static void moveto(lua_State *L, TValue *fr, int idx)
Definition: lapi.cpp:200
#define lua_number2unsigned(i, n)
Definition: llimits.h:236
ptrdiff_t extra
Definition: lstate.h:74
void luaC_fullgc(lua_State *L, int isemergency)
Definition: lgc.cpp:1188
void luaV_settable(lua_State *L, const TValue *t, TValue *key, StkId val)
Definition: lvm.cpp:135
#define LUA_GCRESTART
Definition: lua.h:281
#define setthvalue(L, obj, x)
Definition: lobject.h:215
#define l_isfalse(o)
Definition: lobject.h:169
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)
Definition: lapi.cpp:220
LUA_API int lua_getctx(lua_State *L, int *ctx)
Definition: lapi.cpp:874
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
Definition: lstring.cpp:155
#define luaC_objbarrier(L, p, o)
Definition: lgc.h:132
GLdouble s
Definition: glew.h:1358
#define setsvalue2s
Definition: lobject.h:253
#define LUA_VERSION_NUM
Definition: lua.h:20
#define LUA_TTABLE
Definition: lua.h:82
int gcstepmul
Definition: lstate.h:140
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
Definition: lapi.cpp:477
lu_byte gcrunning
Definition: lstate.h:124
const std::string version
Definition: game_config.cpp:48
LUA_API void lua_rawget(lua_State *L, int idx)
Definition: lapi.cpp:633
#define isLua(ci)
Definition: lstate.h:105
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 MAXUPVAL
Definition: llimits.h:125
#define ttisCclosure(o)
Definition: lobject.h:142
LUA_API int lua_next(lua_State *L, int idx)
Definition: lapi.cpp:1108
#define LUA_OPEQ
Definition: lua.h:193
lu_mem GCestimate
Definition: lstate.h:117
LUA_API const char * lua_typename(lua_State *L, int t)
Definition: lapi.cpp:249
#define setobj2n
Definition: lobject.h:261
LUA_API void lua_arith(lua_State *L, int op)
Definition: lapi.cpp:287
#define hvalue(o)
Definition: lobject.h:163
lu_byte status
Definition: lstate.h:155
#define checkresults(L, na, nr)
Definition: lapi.cpp:869
#define EXTRA_STACK
Definition: lstate.h:46
GLclampf f
Definition: glew.h:3024
#define adjustresults(L, nres)
Definition: lapi.h:16