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 check(x)   if (!(x)) return 0;
 
#define checkjump(pt, pc)   check(0 <= pc && pc < pt->sizecode)
 
#define checkreg(pt, reg)   check((reg) < (pt)->maxstacksize)
 
#define checkopenop(pt, pc)   luaG_checkopenop((pt)->code[(pc)+1])
 

Functions

static const char * getfuncname (lua_State *L, CallInfo *ci, const char **name)
 
static int currentpc (lua_State *L, CallInfo *ci)
 
static int currentline (lua_State *L, CallInfo *ci)
 
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 Protogetluaproto (CallInfo *ci)
 
static const char * findlocal (lua_State *L, CallInfo *ci, int n)
 
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 info_tailcall (lua_Debug *ar)
 
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 int precheck (const Proto *pt)
 
int luaG_checkopenop (Instruction i)
 
static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode)
 
static Instruction symbexec (const Proto *pt, int lastpc, int reg)
 
int luaG_checkcode (const Proto *pt)
 
static const char * kname (Proto *p, int c)
 
static const char * getobjname (lua_State *L, CallInfo *ci, int stackpos, const char **name)
 
static int isinstack (CallInfo *ci, const TValue *o)
 
void luaG_typeerror (lua_State *L, const TValue *o, const char *op)
 
void luaG_concaterror (lua_State *L, StkId p1, StkId p2)
 
void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2)
 
int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2)
 
static void addinfo (lua_State *L, const char *msg)
 
void luaG_errormsg (lua_State *L)
 
void luaG_runerror (lua_State *L, const char *fmt,...)
 

Macro Definition Documentation

◆ check

◆ checkjump

#define checkjump ( pt,
pc )   check(0 <= pc && pc < pt->sizecode)

Definition at line 270 of file lua-5.1.5/src/ldebug.c.

◆ checkopenop

#define checkopenop ( pt,
pc )   luaG_checkopenop((pt)->code[(pc)+1])

Definition at line 288 of file lua-5.1.5/src/ldebug.c.

Referenced by symbexec().

◆ checkreg

#define checkreg ( pt,
reg )   check((reg) < (pt)->maxstacksize)

Definition at line 272 of file lua-5.1.5/src/ldebug.c.

Referenced by checkArgMode(), and symbexec().

◆ ldebug_c

#define ldebug_c

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

◆ LUA_CORE

#define LUA_CORE

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

Function Documentation

◆ addinfo()

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

Definition at line 607 of file lua-5.1.5/src/ldebug.c.

607 {
608 CallInfo *ci = L->ci;
609 if (isLua(ci)) { /* is Lua code? */
610 char buff[LUA_IDSIZE]; /* add file:line information */
611 int line = currentline(L, ci);
612 luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
613 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
614 }
615}
static int currentline(lua_State *L, CallInfo *ci)
static Proto * getluaproto(CallInfo *ci)
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 isLua(ci)
#define LUA_IDSIZE

References lua_State::ci, currentline(), getluaproto(), 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 193 of file lua-5.1.5/src/ldebug.c.

194 {
195 int status = 1;
196 if (f == NULL) {
197 info_tailcall(ar);
198 return status;
199 }
200 for (; *what; what++) {
201 switch (*what) {
202 case 'S': {
203 funcinfo(ar, f);
204 break;
205 }
206 case 'l': {
207 ar->currentline = (ci) ? currentline(L, ci) : -1;
208 break;
209 }
210 case 'u': {
211 ar->nups = f->c.nupvalues;
212 break;
213 }
214 case 'n': {
215 ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
216 if (ar->namewhat == NULL) {
217 ar->namewhat = ""; /* not found */
218 ar->name = NULL;
219 }
220 break;
221 }
222 case 'L':
223 case 'f': /* handled by lua_getinfo */
224 break;
225 default: status = 0; /* invalid option */
226 }
227 }
228 return status;
229}
#define NULL
Definition gmacros.h:924
static void info_tailcall(lua_Debug *ar)
static void funcinfo(lua_Debug *ar, Closure *cl)
static const char * getfuncname(lua_State *L, CallInfo *ci, const char **name)
const char * name
const char * namewhat

References Closure::c, currentline(), lua_Debug::currentline, funcinfo(), getfuncname(), info_tailcall(), lua_Debug::name, lua_Debug::namewhat, NULL, and lua_Debug::nups.

Referenced by lua_getinfo().

◆ checkArgMode()

static int checkArgMode ( const Proto * pt,
int r,
enum OpArgMask mode )
static

Definition at line 304 of file lua-5.1.5/src/ldebug.c.

304 {
305 switch (mode) {
306 case OpArgN: check(r == 0); break;
307 case OpArgU: break;
308 case OpArgR: checkreg(pt, r); break;
309 case OpArgK:
310 check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize);
311 break;
312 }
313 return 1;
314}
#define checkreg(pt, reg)
#define check(x)
#define ISK(x)
#define INDEXK(r)

References check, checkreg, INDEXK, ISK, Proto::maxstacksize, OpArgK, OpArgN, OpArgR, OpArgU, and Proto::sizek.

Referenced by symbexec().

◆ collectvalidlines()

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

Definition at line 177 of file lua-5.1.5/src/ldebug.c.

177 {
178 if (f == NULL || f->c.isC) {
179 setnilvalue(L->top);
180 }
181 else {
182 Table *t = luaH_new(L, 0, 0);
183 int *lineinfo = f->l.p->lineinfo;
184 int i;
185 for (i=0; i<f->l.p->sizelineinfo; i++)
186 setbvalue(luaH_setnum(L, t, lineinfo[i]), 1);
187 sethvalue(L, L->top, t);
188 }
189 incr_top(L);
190}
#define incr_top(L)
#define setbvalue(obj, x)
#define sethvalue(L, obj, x)
#define setnilvalue(obj)
TValue * luaH_setnum(lua_State *L, Table *t, int key)
Table * luaH_new(lua_State *L, int narray, int nhash)
struct Proto * p

References Closure::c, incr_top, Closure::l, Proto::lineinfo, luaH_new(), luaH_setnum(), NULL, LClosure::p, setbvalue, sethvalue, setnilvalue, Proto::sizelineinfo, and lua_State::top.

Referenced by lua_getinfo().

◆ currentline()

static int currentline ( lua_State * L,
CallInfo * ci )
static

Definition at line 44 of file lua-5.1.5/src/ldebug.c.

44 {
45 int pc = currentpc(L, ci);
46 if (pc < 0)
47 return -1; /* only active lua functions have current-line information */
48 else
49 return getline(ci_func(ci)->l.p, pc);
50}
static int currentpc(lua_State *L, CallInfo *ci)
#define getline(f, pc)
#define ci_func(ci)

References ci_func, currentpc(), and getline.

Referenced by addinfo(), auxgetinfo(), collectvalidlines(), and nextline().

◆ currentpc()

static int currentpc ( lua_State * L,
CallInfo * ci )
static

Definition at line 36 of file lua-5.1.5/src/ldebug.c.

36 {
37 if (!isLua(ci)) return -1; /* function is not a Lua function? */
38 if (ci == L->ci)
39 ci->savedpc = L->savedpc;
40 return pcRel(ci->savedpc, ci_func(ci)->l.p);
41}
#define pcRel(pc, p)
const Instruction * savedpc
const Instruction * savedpc

References lua_State::ci, ci_func, isLua, pcRel, CallInfo::savedpc, and lua_State::savedpc.

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

◆ findlocal()

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

Definition at line 112 of file lua-5.1.5/src/ldebug.c.

112 {
113 const char *name;
114 Proto *fp = getluaproto(ci);
115 if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)
116 return name; /* is a local variable in a Lua function */
117 else {
118 StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;
119 if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */
120 return "(*temporary)";
121 else
122 return NULL;
123 }
124}
const char * name
Definition lsqlite3.c:2154
const char * luaF_getlocalname(const Proto *f, int local_number, int pc)

References CallInfo::base, lua_State::ci, currentpc(), getluaproto(), luaF_getlocalname(), name, NULL, and lua_State::top.

Referenced by lua_getlocal(), and lua_setlocal().

◆ funcinfo()

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

Definition at line 150 of file lua-5.1.5/src/ldebug.c.

150 {
151 if (cl->c.isC) {
152 ar->source = "=[C]";
153 ar->linedefined = -1;
154 ar->lastlinedefined = -1;
155 ar->what = "C";
156 }
157 else {
158 ar->source = getstr(cl->l.p->source);
159 ar->linedefined = cl->l.p->linedefined;
161 ar->what = (ar->linedefined == 0) ? "main" : "Lua";
162 }
164}
TString * source
const char * what
const char * source
char short_src[LUA_IDSIZE]

References Closure::c, getstr, Closure::l, Proto::lastlinedefined, lua_Debug::lastlinedefined, Proto::linedefined, lua_Debug::linedefined, LUA_IDSIZE, luaO_chunkid(), 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 544 of file lua-5.1.5/src/ldebug.c.

544 {
545 Instruction i;
546 if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))
547 return NULL; /* calling function is not Lua (or is unknown) */
548 ci--; /* calling function */
549 i = ci_func(ci)->l.p->code[currentpc(L, ci)];
550 if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
552 return getobjname(L, ci, GETARG_A(i), name);
553 else
554 return NULL; /* no useful name can be found */
555}
static const char * getobjname(lua_State *L, CallInfo *ci, int stackpos, const char **name)
lu_int32 Instruction
#define GETARG_A(i)
#define GET_OPCODE(i)
struct CallInfo::@64::@65 l

References ci_func, currentpc(), GET_OPCODE, GETARG_A, getobjname(), isLua, CallInfo::l, name, NULL, OP_CALL, OP_TAILCALL, OP_TFORLOOP, and CallInfo::tailcalls.

Referenced by auxgetinfo().

◆ getluaproto()

static Proto * getluaproto ( CallInfo * ci)
static

Definition at line 107 of file lua-5.1.5/src/ldebug.c.

107 {
108 return (isLua(ci) ? ci_func(ci)->l.p : NULL);
109}

References ci_func, isLua, and NULL.

Referenced by addinfo(), and findlocal().

◆ getobjname()

static const char * getobjname ( lua_State * L,
CallInfo * ci,
int stackpos,
const char ** name )
static

Definition at line 497 of file lua-5.1.5/src/ldebug.c.

498 {
499 if (isLua(ci)) { /* a Lua function? */
500 Proto *p = ci_func(ci)->l.p;
501 int pc = currentpc(L, ci);
502 Instruction i;
503 *name = luaF_getlocalname(p, stackpos+1, pc);
504 if (*name) /* is a local? */
505 return "local";
506 i = symbexec(p, pc, stackpos); /* try symbolic execution */
507 lua_assert(pc != -1);
508 switch (GET_OPCODE(i)) {
509 case OP_GETGLOBAL: {
510 int g = GETARG_Bx(i); /* global index */
511 lua_assert(ttisstring(&p->k[g]));
512 *name = svalue(&p->k[g]);
513 return "global";
514 }
515 case OP_MOVE: {
516 int a = GETARG_A(i);
517 int b = GETARG_B(i); /* move from `b' to `a' */
518 if (b < a)
519 return getobjname(L, ci, b, name); /* get name for `b' */
520 break;
521 }
522 case OP_GETTABLE: {
523 int k = GETARG_C(i); /* key index */
524 *name = kname(p, k);
525 return "field";
526 }
527 case OP_GETUPVAL: {
528 int u = GETARG_B(i); /* upvalue index */
529 *name = p->upvalues ? getstr(p->upvalues[u]) : "?";
530 return "upvalue";
531 }
532 case OP_SELF: {
533 int k = GETARG_C(i); /* key index */
534 *name = kname(p, k);
535 return "method";
536 }
537 default: break;
538 }
539 }
540 return NULL; /* no useful name found */
541}
static Instruction symbexec(const Proto *pt, int lastpc, int reg)
static const char * kname(Proto *p, int c)
#define lua_assert(c)
#define ttisstring(o)
#define svalue(o)
#define GETARG_B(i)
#define GETARG_Bx(i)
#define GETARG_C(i)
struct Proto ** p
TString ** upvalues

References ci_func, currentpc(), GET_OPCODE, GETARG_A, GETARG_B, GETARG_Bx, GETARG_C, getobjname(), getstr, isLua, Proto::k, kname(), lua_assert, luaF_getlocalname(), name, NULL, OP_GETGLOBAL, OP_GETTABLE, OP_GETUPVAL, OP_MOVE, OP_SELF, Proto::p, svalue, symbexec(), ttisstring, and Proto::upvalues.

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

◆ info_tailcall()

static void info_tailcall ( lua_Debug * ar)
static

Definition at line 167 of file lua-5.1.5/src/ldebug.c.

167 {
168 ar->name = ar->namewhat = "";
169 ar->what = "tail";
170 ar->lastlinedefined = ar->linedefined = ar->currentline = -1;
171 ar->source = "=(tail call)";
173 ar->nups = 0;
174}

References lua_Debug::currentline, lua_Debug::lastlinedefined, lua_Debug::linedefined, LUA_IDSIZE, luaO_chunkid(), lua_Debug::name, lua_Debug::namewhat, lua_Debug::nups, lua_Debug::short_src, lua_Debug::source, and lua_Debug::what.

Referenced by auxgetinfo().

◆ isinstack()

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

Definition at line 559 of file lua-5.1.5/src/ldebug.c.

559 {
560 StkId p;
561 for (p = ci->base; p < ci->top; p++)
562 if (o == p) return 1;
563 return 0;
564}

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

Referenced by luaG_typeerror().

◆ kname()

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

Definition at line 489 of file lua-5.1.5/src/ldebug.c.

489 {
490 if (ISK(c) && ttisstring(&p->k[INDEXK(c)]))
491 return svalue(&p->k[INDEXK(c)]);
492 else
493 return "?";
494}

References INDEXK, ISK, Proto::k, svalue, and ttisstring.

Referenced by getobjname().

◆ lua_gethook()

LUA_API lua_Hook lua_gethook ( lua_State * L)

Definition at line 69 of file lua-5.1.5/src/ldebug.c.

69 {
70 return L->hook;
71}

References lua_State::hook.

Referenced by db_gethook(), db_gethook(), db_gethook(), and db_gethook().

◆ lua_gethookcount()

LUA_API int lua_gethookcount ( lua_State * L)

Definition at line 79 of file lua-5.1.5/src/ldebug.c.

79 {
80 return L->basehookcount;
81}

References lua_State::basehookcount.

Referenced by db_gethook(), db_gethook(), db_gethook(), and db_gethook().

◆ lua_gethookmask()

LUA_API int lua_gethookmask ( lua_State * L)

Definition at line 74 of file lua-5.1.5/src/ldebug.c.

74 {
75 return L->hookmask;
76}

References lua_State::hookmask.

Referenced by db_gethook(), db_gethook(), db_gethook(), and db_gethook().

◆ lua_getinfo()

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

Definition at line 232 of file lua-5.1.5/src/ldebug.c.

232 {
233 int status;
234 Closure *f = NULL;
235 CallInfo *ci = NULL;
236 lua_lock(L);
237 if (*what == '>') {
238 StkId func = L->top - 1;
239 luai_apicheck(L, ttisfunction(func));
240 what++; /* skip the '>' */
241 f = clvalue(func);
242 L->top--; /* pop function */
243 }
244 else if (ar->i_ci != 0) { /* no tail call? */
245 ci = L->base_ci + ar->i_ci;
247 f = clvalue(ci->func);
248 }
249 status = auxgetinfo(L, what, ar, f, ci);
250 if (strchr(what, 'f')) {
251 if (f == NULL) setnilvalue(L->top);
252 else setclvalue(L, L->top, f);
253 incr_top(L);
254 }
255 if (strchr(what, 'L'))
256 collectvalidlines(L, f);
257 lua_unlock(L);
258 return status;
259}
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 lua_unlock(L)
#define lua_lock(L)
#define ttisfunction(o)
#define clvalue(o)
#define setclvalue(L, obj, x)
#define luai_apicheck(L, o)

References auxgetinfo(), lua_State::base_ci, clvalue, collectvalidlines(), CallInfo::func, lua_Debug::i_ci, incr_top, lua_assert, lua_lock, lua_unlock, luai_apicheck, NULL, setclvalue, setnilvalue, lua_State::top, and ttisfunction.

Referenced by checkupval(), db_errorfb(), db_getinfo(), db_getinfo(), db_getinfo(), db_getinfo(), getfunc(), hookf(), hookf(), hookf(), hookf(), luaL_argerror(), luaL_argerror(), luaL_traceback(), luaL_where(), pushglobalfuncname(), pushglobalfuncname(), pushglobalfuncname(), and setfenv().

◆ lua_getlocal()

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

Definition at line 127 of file lua-5.1.5/src/ldebug.c.

127 {
128 CallInfo *ci = L->base_ci + ar->i_ci;
129 const char *name = findlocal(L, ci, n);
130 lua_lock(L);
131 if (name)
132 luaA_pushobject(L, ci->base + (n - 1));
133 lua_unlock(L);
134 return name;
135}
void luaA_pushobject(lua_State *L, const TValue *o)
static const char * findlocal(lua_State *L, CallInfo *ci, int n)

References CallInfo::base, lua_State::base_ci, findlocal(), lua_Debug::i_ci, lua_lock, lua_unlock, luaA_pushobject(), and name.

Referenced by db_getlocal(), db_getlocal(), db_getlocal(), and db_getlocal().

◆ lua_getstack()

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

Definition at line 84 of file lua-5.1.5/src/ldebug.c.

84 {
85 int status;
86 CallInfo *ci;
87 lua_lock(L);
88 for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {
89 level--;
90 if (f_isLua(ci)) /* Lua function? */
91 level -= ci->tailcalls; /* skip lost tail calls */
92 }
93 if (level == 0 && ci > L->base_ci) { /* level found? */
94 status = 1;
95 ar->i_ci = cast_int(ci - L->base_ci);
96 }
97 else if (level < 0) { /* level is of a lost tail call? */
98 status = 1;
99 ar->i_ci = 0;
100 }
101 else status = 0; /* no such level */
102 lua_unlock(L);
103 return status;
104}
#define cast_int(i)
#define f_isLua(ci)

References lua_State::base_ci, cast_int, lua_State::ci, f_isLua, lua_Debug::i_ci, lua_lock, lua_unlock, and CallInfo::tailcalls.

Referenced by auxstatus(), costatus(), countlevels(), db_errorfb(), db_getinfo(), db_getinfo(), db_getinfo(), db_getinfo(), db_getlocal(), db_getlocal(), db_getlocal(), db_getlocal(), db_setlocal(), db_setlocal(), db_setlocal(), db_setlocal(), getfunc(), lastlevel(), lastlevel(), luaB_costatus(), luaB_costatus(), luaL_argerror(), luaL_argerror(), luaL_traceback(), luaL_where(), and setfenv().

◆ lua_sethook()

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

Definition at line 56 of file lua-5.1.5/src/ldebug.c.

56 {
57 if (func == NULL || mask == 0) { /* turn off hooks? */
58 mask = 0;
59 func = NULL;
60 }
61 L->hook = func;
62 L->basehookcount = count;
65 return 1;
66}
#define resethookcount(L)
#define cast_byte(i)
#define mask(n)

References lua_State::basehookcount, cast_byte, lua_State::hook, lua_State::hookmask, mask, NULL, and resethookcount.

Referenced by db_sethook(), db_sethook(), db_sethook(), db_sethook(), laction(), laction(), laction(), laction(), lstop(), lstop(), lstop(), and lstop().

◆ lua_setlocal()

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

Definition at line 138 of file lua-5.1.5/src/ldebug.c.

138 {
139 CallInfo *ci = L->base_ci + ar->i_ci;
140 const char *name = findlocal(L, ci, n);
141 lua_lock(L);
142 if (name)
143 setobjs2s(L, ci->base + (n - 1), L->top - 1);
144 L->top--; /* pop value */
145 lua_unlock(L);
146 return name;
147}
#define setobjs2s

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

Referenced by db_setlocal(), db_setlocal(), db_setlocal(), and db_setlocal().

◆ luaG_aritherror()

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

Definition at line 588 of file lua-5.1.5/src/ldebug.c.

588 {
589 TValue temp;
590 if (luaV_tonumber(p1, &temp) == NULL)
591 p2 = p1; /* first operand is wrong */
592 luaG_typeerror(L, p2, "perform arithmetic on");
593}
void luaG_typeerror(lua_State *L, const TValue *o, const char *op)
const TValue * luaV_tonumber(const TValue *obj, TValue *n)

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

Referenced by Arith(), and luaV_arith().

◆ luaG_checkcode()

int luaG_checkcode ( const Proto * pt)

Definition at line 484 of file lua-5.1.5/src/ldebug.c.

484 {
485 return (symbexec(pt, pt->sizecode, NO_REG) != 0);
486}
#define NO_REG

References NO_REG, Proto::sizecode, and symbexec().

Referenced by close_func(), and LoadFunction().

◆ luaG_checkopenop()

int luaG_checkopenop ( Instruction i)

Definition at line 290 of file lua-5.1.5/src/ldebug.c.

290 {
291 switch (GET_OPCODE(i)) {
292 case OP_CALL:
293 case OP_TAILCALL:
294 case OP_RETURN:
295 case OP_SETLIST: {
296 check(GETARG_B(i) == 0);
297 return 1;
298 }
299 default: return 0; /* invalid instruction after an open call */
300 }
301}

References check, GET_OPCODE, GETARG_B, OP_CALL, OP_RETURN, OP_SETLIST, and OP_TAILCALL.

Referenced by luaV_execute().

◆ luaG_concaterror()

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

Definition at line 581 of file lua-5.1.5/src/ldebug.c.

581 {
582 if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
583 lua_assert(!ttisstring(p1) && !ttisnumber(p1));
584 luaG_typeerror(L, p1, "concatenate");
585}
#define ttisnumber(o)

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

Referenced by luaT_trybinTM(), luaT_tryconcatTM(), luaV_concat(), and luaV_concat().

◆ luaG_errormsg()

void luaG_errormsg ( lua_State * L)

Definition at line 618 of file lua-5.1.5/src/ldebug.c.

618 {
619 if (L->errfunc != 0) { /* is there an error handling function? */
620 StkId errfunc = restorestack(L, L->errfunc);
621 if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
622 setobjs2s(L, L->top, L->top - 1); /* move argument */
623 setobjs2s(L, L->top - 1, errfunc); /* push function */
624 incr_top(L);
625 luaD_call(L, L->top - 2, 1); /* call it */
626 }
628}
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, incr_top, LUA_ERRERR, LUA_ERRRUN, luaD_call(), luaD_throw(), restorestack, setobjs2s, lua_State::top, and ttisfunction.

Referenced by lua_error(), and luaG_runerror().

◆ luaG_ordererror()

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

Definition at line 596 of file lua-5.1.5/src/ldebug.c.

596 {
597 const char *t1 = luaT_typenames[ttype(p1)];
598 const char *t2 = luaT_typenames[ttype(p2)];
599 if (t1[2] == t2[2])
600 luaG_runerror(L, "attempt to compare two %s values", t1);
601 else
602 luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
603 return 0;
604}
void luaG_runerror(lua_State *L, const char *fmt,...)
#define ttype(o)
const char *const luaT_typenames[]

References luaG_runerror(), luaT_typenames, and ttype.

Referenced by lessequal(), luaT_callorderTM(), luaV_lessequal(), and luaV_lessthan().

◆ luaG_runerror()

◆ luaG_typeerror()

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

Definition at line 567 of file lua-5.1.5/src/ldebug.c.

567 {
568 const char *name = NULL;
569 const char *t = luaT_typenames[ttype(o)];
570 const char *kind = (isinstack(L->ci, o)) ?
571 getobjname(L, L->ci, cast_int(o - L->base), &name) :
572 NULL;
573 if (kind)
574 luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
575 op, kind, name, t);
576 else
577 luaG_runerror(L, "attempt to %s a %s value", op, t);
578}
static int isinstack(CallInfo *ci, const TValue *o)
#define LUA_QS

References lua_State::base, cast_int, lua_State::ci, getobjname(), isinstack(), LUA_QS, luaG_runerror(), luaT_typenames, name, NULL, and ttype.

Referenced by luaG_aritherror(), luaG_concaterror(), luaV_execute(), luaV_finishget(), luaV_finishset(), luaV_finishset(), luaV_gettable(), luaV_objlen(), luaV_settable(), tryfuncTM(), tryfuncTM(), and tryfuncTM().

◆ precheck()

static int precheck ( const Proto * pt)
static

Definition at line 276 of file lua-5.1.5/src/ldebug.c.

276 {
280 (pt->is_vararg & VARARG_HASARG));
281 check(pt->sizeupvalues <= pt->nups);
282 check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
283 check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
284 return 1;
285}
#define MAXSTACK
#define VARARG_HASARG
#define VARARG_NEEDSARG
Instruction * code
lu_byte maxstacksize

References check, Proto::code, GET_OPCODE, Proto::is_vararg, MAXSTACK, Proto::maxstacksize, Proto::numparams, Proto::nups, OP_RETURN, Proto::sizecode, Proto::sizelineinfo, Proto::sizeupvalues, VARARG_HASARG, and VARARG_NEEDSARG.

Referenced by symbexec().

◆ symbexec()

static Instruction symbexec ( const Proto * pt,
int lastpc,
int reg )
static

Definition at line 317 of file lua-5.1.5/src/ldebug.c.

317 {
318 int pc;
319 int last; /* stores position of last instruction that changed `reg' */
320 last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */
321 check(precheck(pt));
322 for (pc = 0; pc < lastpc; pc++) {
323 Instruction i = pt->code[pc];
324 OpCode op = GET_OPCODE(i);
325 int a = GETARG_A(i);
326 int b = 0;
327 int c = 0;
328 check(op < NUM_OPCODES);
329 checkreg(pt, a);
330 switch (getOpMode(op)) {
331 case iABC: {
332 b = GETARG_B(i);
333 c = GETARG_C(i);
334 check(checkArgMode(pt, b, getBMode(op)));
335 check(checkArgMode(pt, c, getCMode(op)));
336 break;
337 }
338 case iABx: {
339 b = GETARG_Bx(i);
340 if (getBMode(op) == OpArgK) check(b < pt->sizek);
341 break;
342 }
343 case iAsBx: {
344 b = GETARG_sBx(i);
345 if (getBMode(op) == OpArgR) {
346 int dest = pc+1+b;
347 check(0 <= dest && dest < pt->sizecode);
348 if (dest > 0) {
349 int j;
350 /* check that it does not jump to a setlist count; this
351 is tricky, because the count from a previous setlist may
352 have the same value of an invalid setlist; so, we must
353 go all the way back to the first of them (if any) */
354 for (j = 0; j < dest; j++) {
355 Instruction d = pt->code[dest-1-j];
356 if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;
357 }
358 /* if 'j' is even, previous value is not a setlist (even if
359 it looks like one) */
360 check((j&1) == 0);
361 }
362 }
363 break;
364 }
365 }
366 if (testAMode(op)) {
367 if (a == reg) last = pc; /* change register `a' */
368 }
369 if (testTMode(op)) {
370 check(pc+2 < pt->sizecode); /* check skip */
371 check(GET_OPCODE(pt->code[pc+1]) == OP_JMP);
372 }
373 switch (op) {
374 case OP_LOADBOOL: {
375 if (c == 1) { /* does it jump? */
376 check(pc+2 < pt->sizecode); /* check its jump */
377 check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST ||
378 GETARG_C(pt->code[pc+1]) != 0);
379 }
380 break;
381 }
382 case OP_LOADNIL: {
383 if (a <= reg && reg <= b)
384 last = pc; /* set registers from `a' to `b' */
385 break;
386 }
387 case OP_GETUPVAL:
388 case OP_SETUPVAL: {
389 check(b < pt->nups);
390 break;
391 }
392 case OP_GETGLOBAL:
393 case OP_SETGLOBAL: {
394 check(ttisstring(&pt->k[b]));
395 break;
396 }
397 case OP_SELF: {
398 checkreg(pt, a+1);
399 if (reg == a+1) last = pc;
400 break;
401 }
402 case OP_CONCAT: {
403 check(b < c); /* at least two operands */
404 break;
405 }
406 case OP_TFORLOOP: {
407 check(c >= 1); /* at least one result (control variable) */
408 checkreg(pt, a+2+c); /* space for results */
409 if (reg >= a+2) last = pc; /* affect all regs above its base */
410 break;
411 }
412 case OP_FORLOOP:
413 case OP_FORPREP:
414 checkreg(pt, a+3);
415 /* go through */
416 case OP_JMP: {
417 int dest = pc+1+b;
418 /* not full check and jump is forward and do not skip `lastpc'? */
419 if (reg != NO_REG && pc < dest && dest <= lastpc)
420 pc += b; /* do the jump */
421 break;
422 }
423 case OP_CALL:
424 case OP_TAILCALL: {
425 if (b != 0) {
426 checkreg(pt, a+b-1);
427 }
428 c--; /* c = num. returns */
429 if (c == LUA_MULTRET) {
430 check(checkopenop(pt, pc));
431 }
432 else if (c != 0)
433 checkreg(pt, a+c-1);
434 if (reg >= a) last = pc; /* affect all registers above base */
435 break;
436 }
437 case OP_RETURN: {
438 b--; /* b = num. returns */
439 if (b > 0) checkreg(pt, a+b-1);
440 break;
441 }
442 case OP_SETLIST: {
443 if (b > 0) checkreg(pt, a + b);
444 if (c == 0) {
445 pc++;
446 check(pc < pt->sizecode - 1);
447 }
448 break;
449 }
450 case OP_CLOSURE: {
451 int nup, j;
452 check(b < pt->sizep);
453 nup = pt->p[b]->nups;
454 check(pc + nup < pt->sizecode);
455 for (j = 1; j <= nup; j++) {
456 OpCode op1 = GET_OPCODE(pt->code[pc + j]);
457 check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
458 }
459 if (reg != NO_REG) /* tracing? */
460 pc += nup; /* do not 'execute' these pseudo-instructions */
461 break;
462 }
463 case OP_VARARG: {
465 !(pt->is_vararg & VARARG_NEEDSARG));
466 b--;
467 if (b == LUA_MULTRET) check(checkopenop(pt, pc));
468 checkreg(pt, a+b-1);
469 break;
470 }
471 default: break;
472 }
473 }
474 return pt->code[last];
475}
static int precheck(const Proto *pt)
static int checkArgMode(const Proto *pt, int r, enum OpArgMask mode)
#define checkopenop(pt, pc)
#define VARARG_ISVARARG
#define GETARG_sBx(i)
#define NUM_OPCODES
#define testTMode(m)
#define getCMode(m)
#define testAMode(m)
#define getBMode(m)
#define getOpMode(m)
#define LUA_MULTRET

References check, checkArgMode(), checkopenop, checkreg, Proto::code, GET_OPCODE, GETARG_A, GETARG_B, GETARG_Bx, GETARG_C, GETARG_sBx, getBMode, getCMode, getOpMode, iABC, iABx, iAsBx, Proto::is_vararg, Proto::k, LUA_MULTRET, NO_REG, NUM_OPCODES, Proto::nups, OP_CALL, OP_CLOSURE, OP_CONCAT, OP_FORLOOP, OP_FORPREP, OP_GETGLOBAL, OP_GETUPVAL, OP_JMP, OP_LOADBOOL, OP_LOADNIL, OP_MOVE, OP_RETURN, OP_SELF, OP_SETGLOBAL, OP_SETLIST, OP_SETUPVAL, OP_TAILCALL, OP_TFORLOOP, OP_VARARG, OpArgK, OpArgR, Proto::p, precheck(), Proto::sizecode, testAMode, testTMode, ttisstring, VARARG_ISVARARG, and VARARG_NEEDSARG.

Referenced by getobjname(), and luaG_checkcode().