Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ldebug.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include "lua.h"
#include "lapi.h"
#include "lcode.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"

Go to the source code of this file.

Macros

#define ldebug_c
 
#define LUA_CORE
 
#define noLuaClosure(f)   ((f) == NULL || (f)->c.tt == LUA_TCCL)
 

Functions

static const char * getfuncname (lua_State *L, CallInfo *ci, const char **name)
 
static int currentpc (CallInfo *ci)
 
static int currentline (CallInfo *ci)
 
static void swapextra (lua_State *L)
 
LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count)
 
LUA_API lua_Hook lua_gethook (lua_State *L)
 
LUA_API int lua_gethookmask (lua_State *L)
 
LUA_API int lua_gethookcount (lua_State *L)
 
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar)
 
static const char * upvalname (Proto *p, int uv)
 
static const char * findvararg (CallInfo *ci, int n, StkId *pos)
 
static const char * findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos)
 
LUA_API const char * lua_getlocal (lua_State *L, const lua_Debug *ar, int n)
 
LUA_API const char * lua_setlocal (lua_State *L, const lua_Debug *ar, int n)
 
static void funcinfo (lua_Debug *ar, Closure *cl)
 
static void collectvalidlines (lua_State *L, Closure *f)
 
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, Closure *f, CallInfo *ci)
 
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar)
 
static const char * getobjname (Proto *p, int lastpc, int reg, const char **name)
 
static void kname (Proto *p, int pc, int c, const char **name)
 
static int filterpc (int pc, int jmptarget)
 
static int findsetreg (Proto *p, int lastpc, int reg)
 
static int isinstack (CallInfo *ci, const TValue *o)
 
static const char * getupvalname (CallInfo *ci, const TValue *o, const char **name)
 
l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op)
 
l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2)
 
l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2)
 
l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2)
 
static void addinfo (lua_State *L, const char *msg)
 
l_noret luaG_errormsg (lua_State *L)
 
l_noret luaG_runerror (lua_State *L, const char *fmt,...)
 

Macro Definition Documentation

◆ ldebug_c

#define ldebug_c

Definition at line 13 of file lua-5.2.4/src/ldebug.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 14 of file lua-5.2.4/src/ldebug.c.

◆ noLuaClosure

#define noLuaClosure ( f)    ((f) == NULL || (f)->c.tt == LUA_TCCL)

Definition at line 33 of file lua-5.2.4/src/ldebug.c.

Referenced by auxgetinfo(), collectvalidlines(), and funcinfo().

Function Documentation

◆ addinfo()

static void addinfo ( lua_State * L,
const char * msg )
static

Definition at line 574 of file lua-5.2.4/src/ldebug.c.

574 {
575 CallInfo *ci = L->ci;
576 if (isLua(ci)) { /* is Lua code? */
577 char buff[LUA_IDSIZE]; /* add file:line information */
578 int line = currentline(ci);
579 TString *src = ci_func(ci)->p->source;
580 if (src)
581 luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
582 else { /* no source available; use "?" instead */
583 buff[0] = '?'; buff[1] = '\0';
584 }
585 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
586 }
587}
void luaO_chunkid(char *out, const char *source, size_t bufflen)
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
#define getstr(ts)
#define ci_func(ci)
#define isLua(ci)
#define LUA_IDSIZE
static int currentline(CallInfo *ci)

References lua_State::ci, ci_func, currentline(), getstr, isLua, LUA_IDSIZE, luaO_chunkid(), and luaO_pushfstring().

Referenced by luaG_runerror().

◆ auxgetinfo()

static int auxgetinfo ( lua_State * L,
const char * what,
lua_Debug * ar,
Closure * f,
CallInfo * ci )
static

Definition at line 230 of file lua-5.2.4/src/ldebug.c.

231 {
232 int status = 1;
233 for (; *what; what++) {
234 switch (*what) {
235 case 'S': {
236 funcinfo(ar, f);
237 break;
238 }
239 case 'l': {
240 ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;
241 break;
242 }
243 case 'u': {
244 ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
245 if (noLuaClosure(f)) {
246 ar->isvararg = 1;
247 ar->nparams = 0;
248 }
249 else {
250 ar->isvararg = f->l.p->is_vararg;
251 ar->nparams = f->l.p->numparams;
252 }
253 break;
254 }
255 case 't': {
256 ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;
257 break;
258 }
259 case 'n': {
260 /* calling function is a known Lua function? */
261 if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
262 ar->namewhat = getfuncname(L, ci->previous, &ar->name);
263 else
264 ar->namewhat = NULL;
265 if (ar->namewhat == NULL) {
266 ar->namewhat = ""; /* not found */
267 ar->name = NULL;
268 }
269 break;
270 }
271 case 'L':
272 case 'f': /* handled by lua_getinfo */
273 break;
274 default: status = 0; /* invalid option */
275 }
276 }
277 return status;
278}
#define NULL
Definition gmacros.h:924
#define noLuaClosure(f)
static void funcinfo(lua_Debug *ar, Closure *cl)
static const char * getfuncname(lua_State *L, CallInfo *ci, const char **name)
#define CIST_TAIL
struct CallInfo * previous
struct Proto * p
const char * name
unsigned char nparams
const char * namewhat

References Closure::c, CallInfo::callstatus, CIST_TAIL, lua_Debug::currentline, currentline(), funcinfo(), getfuncname(), Proto::is_vararg, isLua, lua_Debug::istailcall, lua_Debug::isvararg, Closure::l, lua_Debug::name, lua_Debug::namewhat, noLuaClosure, lua_Debug::nparams, NULL, Proto::numparams, lua_Debug::nups, LClosure::p, and CallInfo::previous.

Referenced by lua_getinfo().

◆ collectvalidlines()

static void collectvalidlines ( lua_State * L,
Closure * f )
static

Definition at line 211 of file lua-5.2.4/src/ldebug.c.

211 {
212 if (noLuaClosure(f)) {
213 setnilvalue(L->top);
214 api_incr_top(L);
215 }
216 else {
217 int i;
218 TValue v;
219 int *lineinfo = f->l.p->lineinfo;
220 Table *t = luaH_new(L); /* new table to store active lines */
221 sethvalue(L, L->top, t); /* push it on stack */
222 api_incr_top(L);
223 setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
224 for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
225 luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
226 }
227}
#define api_incr_top(L)
#define setbvalue(obj, x)
#define sethvalue(L, obj, x)
#define setnilvalue(obj)
Table * luaH_new(lua_State *L, int narray, int nhash)
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)

References api_incr_top, Closure::l, Proto::lineinfo, luaH_new(), luaH_setint(), noLuaClosure, LClosure::p, setbvalue, sethvalue, setnilvalue, Proto::sizelineinfo, and lua_State::top.

Referenced by lua_getinfo().

◆ currentline()

static int currentline ( CallInfo * ci)
static

Definition at line 45 of file lua-5.2.4/src/ldebug.c.

45 {
46 return getfuncline(ci_func(ci)->p, currentpc(ci));
47}
static int currentpc(CallInfo *ci)
#define getfuncline(f, pc)

References ci_func, currentpc(), and getfuncline.

Referenced by addinfo(), and auxgetinfo().

◆ currentpc()

static int currentpc ( CallInfo * ci)
static

Definition at line 39 of file lua-5.2.4/src/ldebug.c.

39 {
40 lua_assert(isLua(ci));
41 return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
42}
#define pcRel(pc, p)
#define lua_assert(c)
struct CallInfo::@64::@65 l
const Instruction * savedpc
union CallInfo::@64 u

References ci_func, isLua, CallInfo::l, lua_assert, pcRel, CallInfo::savedpc, and CallInfo::u.

Referenced by currentline(), findlocal(), getfuncname(), and luaG_typeerror().

◆ filterpc()

static int filterpc ( int pc,
int jmptarget )
static

Definition at line 347 of file lua-5.2.4/src/ldebug.c.

347 {
348 if (pc < jmptarget) /* is code conditional (inside a jump)? */
349 return -1; /* cannot know who sets that register */
350 else return pc; /* current position sets that register */
351}

Referenced by findsetreg().

◆ findlocal()

static const char * findlocal ( lua_State * L,
CallInfo * ci,
int n,
StkId * pos )
static

Definition at line 128 of file lua-5.2.4/src/ldebug.c.

129 {
130 const char *name = NULL;
131 StkId base;
132 if (isLua(ci)) {
133 if (n < 0) /* access to vararg values? */
134 return findvararg(ci, -n, pos);
135 else {
136 base = ci->u.l.base;
137 name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
138 }
139 }
140 else
141 base = ci->func + 1;
142 if (name == NULL) { /* no 'standard' name? */
143 StkId limit = (ci == L->ci) ? L->top : ci->next->func;
144 if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
145 name = "(*temporary)"; /* generic name for any valid slot */
146 else
147 return NULL; /* no name */
148 }
149 *pos = base + (n - 1);
150 return name;
151}
const char * name
Definition lsqlite3.c:2154
const char * luaF_getlocalname(const Proto *f, int local_number, int pc)
#define next(ls)
static const char * findvararg(CallInfo *ci, int n, StkId *pos)

References CallInfo::base, lua_State::ci, ci_func, currentpc(), findvararg(), CallInfo::func, isLua, CallInfo::l, luaF_getlocalname(), name, CallInfo::next, NULL, lua_State::top, and CallInfo::u.

Referenced by lua_getlocal(), and lua_setlocal().

◆ findsetreg()

static int findsetreg ( Proto * p,
int lastpc,
int reg )
static

Definition at line 357 of file lua-5.2.4/src/ldebug.c.

357 {
358 int pc;
359 int setreg = -1; /* keep last instruction that changed 'reg' */
360 int jmptarget = 0; /* any code before this address is conditional */
361 for (pc = 0; pc < lastpc; pc++) {
362 Instruction i = p->code[pc];
363 OpCode op = GET_OPCODE(i);
364 int a = GETARG_A(i);
365 switch (op) {
366 case OP_LOADNIL: {
367 int b = GETARG_B(i);
368 if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
369 setreg = filterpc(pc, jmptarget);
370 break;
371 }
372 case OP_TFORCALL: {
373 if (reg >= a + 2) /* affect all regs above its base */
374 setreg = filterpc(pc, jmptarget);
375 break;
376 }
377 case OP_CALL:
378 case OP_TAILCALL: {
379 if (reg >= a) /* affect all registers above base */
380 setreg = filterpc(pc, jmptarget);
381 break;
382 }
383 case OP_JMP: {
384 int b = GETARG_sBx(i);
385 int dest = pc + 1 + b;
386 /* jump is forward and do not skip `lastpc'? */
387 if (pc < dest && dest <= lastpc) {
388 if (dest > jmptarget)
389 jmptarget = dest; /* update 'jmptarget' */
390 }
391 break;
392 }
393 case OP_TEST: {
394 if (reg == a) /* jumped code can change 'a' */
395 setreg = filterpc(pc, jmptarget);
396 break;
397 }
398 default:
399 if (testAMode(op) && reg == a) /* any instruction that set A */
400 setreg = filterpc(pc, jmptarget);
401 break;
402 }
403 }
404 return setreg;
405}
lu_int32 Instruction
#define GETARG_A(i)
#define GETARG_sBx(i)
#define GETARG_B(i)
#define GET_OPCODE(i)
#define testAMode(m)
static int filterpc(int pc, int jmptarget)
Instruction * code

References Proto::code, filterpc(), GET_OPCODE, GETARG_A, GETARG_B, GETARG_sBx, OP_CALL, OP_JMP, OP_LOADNIL, OP_TAILCALL, OP_TEST, OP_TFORCALL, and testAMode.

Referenced by getobjname().

◆ findvararg()

static const char * findvararg ( CallInfo * ci,
int n,
StkId * pos )
static

Definition at line 117 of file lua-5.2.4/src/ldebug.c.

117 {
118 int nparams = clLvalue(ci->func)->p->numparams;
119 if (n >= ci->u.l.base - ci->func - nparams)
120 return NULL; /* no such vararg */
121 else {
122 *pos = ci->func + nparams + n;
123 return "(*vararg)"; /* generic name for any vararg */
124 }
125}
#define clLvalue(o)

References CallInfo::base, clLvalue, CallInfo::func, CallInfo::l, NULL, and CallInfo::u.

Referenced by findlocal().

◆ funcinfo()

static void funcinfo ( lua_Debug * ar,
Closure * cl )
static

Definition at line 193 of file lua-5.2.4/src/ldebug.c.

193 {
194 if (noLuaClosure(cl)) {
195 ar->source = "=[C]";
196 ar->linedefined = -1;
197 ar->lastlinedefined = -1;
198 ar->what = "C";
199 }
200 else {
201 Proto *p = cl->l.p;
202 ar->source = p->source ? getstr(p->source) : "=?";
203 ar->linedefined = p->linedefined;
205 ar->what = (ar->linedefined == 0) ? "main" : "Lua";
206 }
208}
TString * source
const char * what
const char * source
char short_src[LUA_IDSIZE]

References getstr, Closure::l, Proto::lastlinedefined, lua_Debug::lastlinedefined, Proto::linedefined, lua_Debug::linedefined, LUA_IDSIZE, luaO_chunkid(), noLuaClosure, LClosure::p, lua_Debug::short_src, Proto::source, lua_Debug::source, and lua_Debug::what.

Referenced by auxgetinfo().

◆ getfuncname()

static const char * getfuncname ( lua_State * L,
CallInfo * ci,
const char ** name )
static

Definition at line 462 of file lua-5.2.4/src/ldebug.c.

462 {
463 TMS tm;
464 Proto *p = ci_func(ci)->p; /* calling function */
465 int pc = currentpc(ci); /* calling instruction index */
466 Instruction i = p->code[pc]; /* calling instruction */
467 switch (GET_OPCODE(i)) {
468 case OP_CALL:
469 case OP_TAILCALL: /* get function name */
470 return getobjname(p, pc, GETARG_A(i), name);
471 case OP_TFORCALL: { /* for iterator */
472 *name = "for iterator";
473 return "for iterator";
474 }
475 /* all other instructions can call only through metamethods */
476 case OP_SELF:
477 case OP_GETTABUP:
478 case OP_GETTABLE: tm = TM_INDEX; break;
479 case OP_SETTABUP:
480 case OP_SETTABLE: tm = TM_NEWINDEX; break;
481 case OP_EQ: tm = TM_EQ; break;
482 case OP_ADD: tm = TM_ADD; break;
483 case OP_SUB: tm = TM_SUB; break;
484 case OP_MUL: tm = TM_MUL; break;
485 case OP_DIV: tm = TM_DIV; break;
486 case OP_MOD: tm = TM_MOD; break;
487 case OP_POW: tm = TM_POW; break;
488 case OP_UNM: tm = TM_UNM; break;
489 case OP_LEN: tm = TM_LEN; break;
490 case OP_LT: tm = TM_LT; break;
491 case OP_LE: tm = TM_LE; break;
492 case OP_CONCAT: tm = TM_CONCAT; break;
493 default:
494 return NULL; /* else no useful name can be found */
495 }
496 *name = getstr(G(L)->tmname[tm]);
497 return "metamethod";
498}
#define G(L)
@ TM_NEWINDEX
@ TM_MUL
@ TM_INDEX
@ TM_UNM
@ TM_EQ
@ TM_POW
@ TM_DIV
@ TM_LEN
@ TM_SUB
@ TM_ADD
@ TM_LE
@ TM_CONCAT
@ TM_LT
@ TM_MOD
static const char * getobjname(Proto *p, int lastpc, int reg, const char **name)
static TString ** tmname
struct Proto ** p

References ci_func, Proto::code, currentpc(), G, GET_OPCODE, GETARG_A, getobjname(), getstr, name, NULL, OP_ADD, OP_CALL, OP_CONCAT, OP_DIV, OP_EQ, OP_GETTABLE, OP_GETTABUP, OP_LE, OP_LEN, OP_LT, OP_MOD, OP_MUL, OP_POW, OP_SELF, OP_SETTABLE, OP_SETTABUP, OP_SUB, OP_TAILCALL, OP_TFORCALL, OP_UNM, Proto::p, TM_ADD, TM_CONCAT, TM_DIV, TM_EQ, TM_INDEX, TM_LE, TM_LEN, TM_LT, TM_MOD, TM_MUL, TM_NEWINDEX, TM_POW, TM_SUB, TM_UNM, and tmname.

Referenced by auxgetinfo().

◆ getobjname()

static const char * getobjname ( Proto * p,
int lastpc,
int reg,
const char ** name )
static

Definition at line 408 of file lua-5.2.4/src/ldebug.c.

409 {
410 int pc;
411 *name = luaF_getlocalname(p, reg + 1, lastpc);
412 if (*name) /* is a local? */
413 return "local";
414 /* else try symbolic execution */
415 pc = findsetreg(p, lastpc, reg);
416 if (pc != -1) { /* could find instruction? */
417 Instruction i = p->code[pc];
418 OpCode op = GET_OPCODE(i);
419 switch (op) {
420 case OP_MOVE: {
421 int b = GETARG_B(i); /* move from 'b' to 'a' */
422 if (b < GETARG_A(i))
423 return getobjname(p, pc, b, name); /* get name for 'b' */
424 break;
425 }
426 case OP_GETTABUP:
427 case OP_GETTABLE: {
428 int k = GETARG_C(i); /* key index */
429 int t = GETARG_B(i); /* table index */
430 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
431 ? luaF_getlocalname(p, t + 1, pc)
432 : upvalname(p, t);
433 kname(p, pc, k, name);
434 return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
435 }
436 case OP_GETUPVAL: {
437 *name = upvalname(p, GETARG_B(i));
438 return "upvalue";
439 }
440 case OP_LOADK:
441 case OP_LOADKX: {
442 int b = (op == OP_LOADK) ? GETARG_Bx(i)
443 : GETARG_Ax(p->code[pc + 1]);
444 if (ttisstring(&p->k[b])) {
445 *name = svalue(&p->k[b]);
446 return "constant";
447 }
448 break;
449 }
450 case OP_SELF: {
451 int k = GETARG_C(i); /* key index */
452 kname(p, pc, k, name);
453 return "method";
454 }
455 default: break; /* go through to return NULL */
456 }
457 }
458 return NULL; /* could not find reasonable name */
459}
#define ttisstring(o)
#define svalue(o)
#define GETARG_Bx(i)
#define GETARG_C(i)
static int findsetreg(Proto *p, int lastpc, int reg)
static void kname(Proto *p, int pc, int c, const char **name)
static const char * upvalname(Proto *p, int uv)
#define GETARG_Ax(i)
#define LUA_ENV

References Proto::code, findsetreg(), GET_OPCODE, GETARG_A, GETARG_Ax, GETARG_B, GETARG_Bx, GETARG_C, getobjname(), Proto::k, kname(), LUA_ENV, luaF_getlocalname(), name, NULL, OP_GETTABLE, OP_GETTABUP, OP_GETUPVAL, OP_LOADK, OP_LOADKX, OP_MOVE, OP_SELF, svalue, ttisstring, and upvalname().

Referenced by getfuncname(), getobjname(), kname(), and luaG_typeerror().

◆ getupvalname()

static const char * getupvalname ( CallInfo * ci,
const TValue * o,
const char ** name )
static

Definition at line 516 of file lua-5.2.4/src/ldebug.c.

517 {
518 LClosure *c = ci_func(ci);
519 int i;
520 for (i = 0; i < c->nupvalues; i++) {
521 if (c->upvals[i]->v == o) {
522 *name = upvalname(c->p, i);
523 return "upvalue";
524 }
525 }
526 return NULL;
527}

References ci_func, name, NULL, LClosure::p, upvalname(), LClosure::upvals, and UpVal::v.

Referenced by luaG_typeerror().

◆ isinstack()

static int isinstack ( CallInfo * ci,
const TValue * o )
static

Definition at line 508 of file lua-5.2.4/src/ldebug.c.

508 {
509 StkId p;
510 for (p = ci->u.l.base; p < ci->top; p++)
511 if (o == p) return 1;
512 return 0;
513}

References CallInfo::base, CallInfo::l, CallInfo::top, and CallInfo::u.

Referenced by luaG_typeerror().

◆ kname()

static void kname ( Proto * p,
int pc,
int c,
const char ** name )
static

Definition at line 327 of file lua-5.2.4/src/ldebug.c.

327 {
328 if (ISK(c)) { /* is 'c' a constant? */
329 TValue *kvalue = &p->k[INDEXK(c)];
330 if (ttisstring(kvalue)) { /* literal constant? */
331 *name = svalue(kvalue); /* it is its own name */
332 return;
333 }
334 /* else no reasonable name found */
335 }
336 else { /* 'c' is a register */
337 const char *what = getobjname(p, pc, c, name); /* search for 'c' */
338 if (what && *what == 'c') { /* found a constant name? */
339 return; /* 'name' already filled */
340 }
341 /* else no reasonable name found */
342 }
343 *name = "?"; /* no reasonable name found */
344}
#define ISK(x)
#define INDEXK(r)

References getobjname(), INDEXK, ISK, Proto::k, name, svalue, and ttisstring.

Referenced by getobjname().

◆ lua_gethook()

LUA_API lua_Hook lua_gethook ( lua_State * L)

Definition at line 78 of file lua-5.2.4/src/ldebug.c.

78 {
79 return L->hook;
80}

References lua_State::hook.

◆ lua_gethookcount()

LUA_API int lua_gethookcount ( lua_State * L)

Definition at line 88 of file lua-5.2.4/src/ldebug.c.

88 {
89 return L->basehookcount;
90}

References lua_State::basehookcount.

◆ lua_gethookmask()

LUA_API int lua_gethookmask ( lua_State * L)

Definition at line 83 of file lua-5.2.4/src/ldebug.c.

83 {
84 return L->hookmask;
85}

References lua_State::hookmask.

◆ lua_getinfo()

LUA_API int lua_getinfo ( lua_State * L,
const char * what,
lua_Debug * ar )

Definition at line 281 of file lua-5.2.4/src/ldebug.c.

281 {
282 int status;
283 Closure *cl;
284 CallInfo *ci;
285 StkId func;
286 lua_lock(L);
287 swapextra(L);
288 if (*what == '>') {
289 ci = NULL;
290 func = L->top - 1;
291 api_check(L, ttisfunction(func), "function expected");
292 what++; /* skip the '>' */
293 L->top--; /* pop function */
294 }
295 else {
296 ci = ar->i_ci;
297 func = ci->func;
299 }
300 cl = ttisclosure(func) ? clvalue(func) : NULL;
301 status = auxgetinfo(L, what, ar, cl, ci);
302 if (strchr(what, 'f')) {
303 setobjs2s(L, L->top, func);
304 api_incr_top(L);
305 }
306 swapextra(L);
307 if (strchr(what, 'L'))
308 collectvalidlines(L, cl);
309 lua_unlock(L);
310 return status;
311}
#define lua_unlock(L)
#define api_check
#define lua_lock(L)
#define ttisfunction(o)
#define clvalue(o)
#define setobjs2s
static void swapextra(lua_State *L)
static void collectvalidlines(lua_State *L, Closure *f)
static int auxgetinfo(lua_State *L, const char *what, lua_Debug *ar, Closure *f, CallInfo *ci)
#define ttisclosure(o)

References api_check, api_incr_top, auxgetinfo(), clvalue, collectvalidlines(), CallInfo::func, lua_Debug::i_ci, lua_assert, lua_lock, lua_unlock, NULL, setobjs2s, swapextra(), lua_State::top, ttisclosure, and ttisfunction.

◆ lua_getlocal()

LUA_API const char * lua_getlocal ( lua_State * L,
const lua_Debug * ar,
int n )

Definition at line 154 of file lua-5.2.4/src/ldebug.c.

154 {
155 const char *name;
156 lua_lock(L);
157 swapextra(L);
158 if (ar == NULL) { /* information about non-active function? */
159 if (!isLfunction(L->top - 1)) /* not a Lua function? */
160 name = NULL;
161 else /* consider live variables at function start (parameters) */
162 name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
163 }
164 else { /* active function; get information through 'ar' */
165 StkId pos = 0; /* to avoid warnings */
166 name = findlocal(L, ar->i_ci, n, &pos);
167 if (name) {
168 setobj2s(L, L->top, pos);
169 api_incr_top(L);
170 }
171 }
172 swapextra(L);
173 lua_unlock(L);
174 return name;
175}
#define setobj2s
#define isLfunction(o)
static const char * findlocal(lua_State *L, CallInfo *ci, int n, StkId *pos)

References api_incr_top, clLvalue, findlocal(), lua_Debug::i_ci, isLfunction, lua_lock, lua_unlock, luaF_getlocalname(), name, NULL, setobj2s, swapextra(), and lua_State::top.

◆ lua_getstack()

LUA_API int lua_getstack ( lua_State * L,
int level,
lua_Debug * ar )

Definition at line 93 of file lua-5.2.4/src/ldebug.c.

93 {
94 int status;
95 CallInfo *ci;
96 if (level < 0) return 0; /* invalid (negative) level */
97 lua_lock(L);
98 for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)
99 level--;
100 if (level == 0 && ci != &L->base_ci) { /* level found? */
101 status = 1;
102 ar->i_ci = ci;
103 }
104 else status = 0; /* no such level */
105 lua_unlock(L);
106 return status;
107}

References lua_State::base_ci, lua_State::ci, lua_Debug::i_ci, lua_lock, lua_unlock, and CallInfo::previous.

◆ lua_sethook()

LUA_API int lua_sethook ( lua_State * L,
lua_Hook func,
int mask,
int count )

Definition at line 63 of file lua-5.2.4/src/ldebug.c.

63 {
64 if (func == NULL || mask == 0) { /* turn off hooks? */
65 mask = 0;
66 func = NULL;
67 }
68 if (isLua(L->ci))
69 L->oldpc = L->ci->u.l.savedpc;
70 L->hook = func;
71 L->basehookcount = count;
74 return 1;
75}
#define resethookcount(L)
#define cast_byte(i)
#define mask(n)
const Instruction * oldpc

References lua_State::basehookcount, cast_byte, lua_State::ci, lua_State::hook, lua_State::hookmask, isLua, CallInfo::l, mask, NULL, lua_State::oldpc, resethookcount, CallInfo::savedpc, and CallInfo::u.

◆ lua_setlocal()

LUA_API const char * lua_setlocal ( lua_State * L,
const lua_Debug * ar,
int n )

Definition at line 178 of file lua-5.2.4/src/ldebug.c.

178 {
179 StkId pos = 0; /* to avoid warnings */
180 const char *name;
181 lua_lock(L);
182 swapextra(L);
183 name = findlocal(L, ar->i_ci, n, &pos);
184 if (name)
185 setobjs2s(L, pos, L->top - 1);
186 L->top--; /* pop value */
187 swapextra(L);
188 lua_unlock(L);
189 return name;
190}

References findlocal(), lua_Debug::i_ci, lua_lock, lua_unlock, name, setobjs2s, swapextra(), and lua_State::top.

◆ luaG_aritherror()

l_noret luaG_aritherror ( lua_State * L,
const TValue * p1,
const TValue * p2 )

Definition at line 556 of file lua-5.2.4/src/ldebug.c.

556 {
557 TValue temp;
558 if (luaV_tonumber(p1, &temp) == NULL)
559 p2 = p1; /* first operand is wrong */
560 luaG_typeerror(L, p2, "perform arithmetic on");
561}
const TValue * luaV_tonumber(const TValue *obj, TValue *n)
l_noret luaG_typeerror(lua_State *L, const TValue *o, const char *op)

References luaG_typeerror(), luaV_tonumber(), and NULL.

◆ luaG_concaterror()

l_noret luaG_concaterror ( lua_State * L,
StkId p1,
StkId p2 )

Definition at line 549 of file lua-5.2.4/src/ldebug.c.

549 {
550 if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
551 lua_assert(!ttisstring(p1) && !ttisnumber(p1));
552 luaG_typeerror(L, p1, "concatenate");
553}
#define ttisnumber(o)

References lua_assert, luaG_typeerror(), ttisnumber, and ttisstring.

◆ luaG_errormsg()

l_noret luaG_errormsg ( lua_State * L)

Definition at line 590 of file lua-5.2.4/src/ldebug.c.

590 {
591 if (L->errfunc != 0) { /* is there an error handling function? */
592 StkId errfunc = restorestack(L, L->errfunc);
593 if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
594 setobjs2s(L, L->top, L->top - 1); /* move argument */
595 setobjs2s(L, L->top - 1, errfunc); /* push function */
596 L->top++;
597 luaD_call(L, L->top - 2, 1, 0); /* call it */
598 }
600}
void luaD_call(lua_State *L, StkId func, int nResults)
void luaD_throw(lua_State *L, int errcode)
#define restorestack(L, n)
#define LUA_ERRERR
#define LUA_ERRRUN

References lua_State::errfunc, LUA_ERRERR, LUA_ERRRUN, luaD_call(), luaD_throw(), restorestack, setobjs2s, lua_State::top, and ttisfunction.

Referenced by luaG_runerror().

◆ luaG_ordererror()

l_noret luaG_ordererror ( lua_State * L,
const TValue * p1,
const TValue * p2 )

Definition at line 564 of file lua-5.2.4/src/ldebug.c.

564 {
565 const char *t1 = objtypename(p1);
566 const char *t2 = objtypename(p2);
567 if (t1 == t2)
568 luaG_runerror(L, "attempt to compare two %s values", t1);
569 else
570 luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
571}
l_noret luaG_runerror(lua_State *L, const char *fmt,...)
#define objtypename(x)

References luaG_runerror(), and objtypename.

◆ luaG_runerror()

l_noret luaG_runerror ( lua_State * L,
const char * fmt,
... )

Definition at line 603 of file lua-5.2.4/src/ldebug.c.

603 {
604 va_list argp;
605 va_start(argp, fmt);
606 addinfo(L, luaO_pushvfstring(L, fmt, argp));
607 va_end(argp);
608 luaG_errormsg(L);
609}
const char * luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)
static void addinfo(lua_State *L, const char *msg)
l_noret luaG_errormsg(lua_State *L)

References addinfo(), luaG_errormsg(), and luaO_pushvfstring().

Referenced by luaG_ordererror(), and luaG_typeerror().

◆ luaG_typeerror()

l_noret luaG_typeerror ( lua_State * L,
const TValue * o,
const char * op )

Definition at line 530 of file lua-5.2.4/src/ldebug.c.

530 {
531 CallInfo *ci = L->ci;
532 const char *name = NULL;
533 const char *t = objtypename(o);
534 const char *kind = NULL;
535 if (isLua(ci)) {
536 kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
537 if (!kind && isinstack(ci, o)) /* no? try a register */
538 kind = getobjname(ci_func(ci)->p, currentpc(ci),
539 cast_int(o - ci->u.l.base), &name);
540 }
541 if (kind)
542 luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
543 op, kind, name, t);
544 else
545 luaG_runerror(L, "attempt to %s a %s value", op, t);
546}
#define cast_int(i)
#define LUA_QS
static int isinstack(CallInfo *ci, const TValue *o)
static const char * getupvalname(CallInfo *ci, const TValue *o, const char **name)

References CallInfo::base, cast_int, lua_State::ci, ci_func, currentpc(), getobjname(), getupvalname(), isinstack(), isLua, CallInfo::l, LUA_QS, luaG_runerror(), name, NULL, objtypename, and CallInfo::u.

Referenced by luaG_aritherror(), and luaG_concaterror().

◆ swapextra()

static void swapextra ( lua_State * L)
static

Definition at line 50 of file lua-5.2.4/src/ldebug.c.

50 {
51 if (L->status == LUA_YIELD) {
52 CallInfo *ci = L->ci; /* get function that yielded */
53 StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
54 ci->func = restorestack(L, ci->extra);
55 ci->extra = savestack(L, temp);
56 }
57}
#define savestack(L, p)
#define LUA_YIELD

References lua_State::ci, CallInfo::extra, CallInfo::func, LUA_YIELD, restorestack, savestack, and lua_State::status.

Referenced by lua_getinfo(), lua_getlocal(), and lua_setlocal().

◆ upvalname()

static const char * upvalname ( Proto * p,
int uv )
static

Definition at line 110 of file lua-5.2.4/src/ldebug.c.

110 {
111 TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
112 if (s == NULL) return "?";
113 else return getstr(s);
114}
#define check_exp(c, e)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318
TString ** upvalues

References check_exp, getstr, NULL, s, and Proto::upvalues.

Referenced by getobjname(), and getupvalname().