Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ldblib.c File Reference
#include "lprefix.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

Go to the source code of this file.

Macros

#define ldblib_c
 
#define LUA_LIB
 

Functions

static void checkstack (lua_State *L, lua_State *L1, int n)
 
static int db_getregistry (lua_State *L)
 
static int db_getmetatable (lua_State *L)
 
static int db_setmetatable (lua_State *L)
 
static int db_getuservalue (lua_State *L)
 
static int db_setuservalue (lua_State *L)
 
static lua_Stategetthread (lua_State *L, int *arg)
 
static void settabss (lua_State *L, const char *k, const char *v)
 
static void settabsi (lua_State *L, const char *k, int v)
 
static void settabsb (lua_State *L, const char *k, int v)
 
static void treatstackoption (lua_State *L, lua_State *L1, const char *fname)
 
static int db_getinfo (lua_State *L)
 
static int db_getlocal (lua_State *L)
 
static int db_setlocal (lua_State *L)
 
static int auxupvalue (lua_State *L, int get)
 
static int db_getupvalue (lua_State *L)
 
static int db_setupvalue (lua_State *L)
 
static void * checkupval (lua_State *L, int argf, int argnup, int *pnup)
 
static int db_upvalueid (lua_State *L)
 
static int db_upvaluejoin (lua_State *L)
 
static void hookf (lua_State *L, lua_Debug *ar)
 
static int makemask (const char *smask, int count)
 
static char * unmakemask (int mask, char *smask)
 
static int db_sethook (lua_State *L)
 
static int db_gethook (lua_State *L)
 
static int db_debug (lua_State *L)
 
static int db_traceback (lua_State *L)
 
static int db_setcstacklimit (lua_State *L)
 
LUAMOD_API int luaopen_debug (lua_State *L)
 

Variables

static const char *const HOOKKEY = "_HOOKKEY"
 
static const luaL_Reg dblib []
 

Macro Definition Documentation

◆ ldblib_c

#define ldblib_c

Definition at line 7 of file lua-5.4.3/src/ldblib.c.

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file lua-5.4.3/src/ldblib.c.

Function Documentation

◆ auxupvalue()

static int auxupvalue ( lua_State * L,
int get )
static

Definition at line 258 of file lua-5.4.3/src/ldblib.c.

258 {
259 const char *name;
260 int n = (int)luaL_checkinteger(L, 2); /* upvalue index */
261 luaL_checktype(L, 1, LUA_TFUNCTION); /* closure */
262 name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
263 if (name == NULL) return 0;
265 lua_insert(L, -(get+1)); /* no-op if get is false */
266 return get + 1;
267}
#define NULL
Definition gmacros.h:924
const char * name
Definition lsqlite3.c:2154
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API const char * lua_getupvalue(lua_State *L, int funcindex, int n)
LUA_API const char * lua_setupvalue(lua_State *L, int funcindex, int n)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
#define LUA_TFUNCTION
#define lua_insert(L, idx)

References lua_getupvalue(), lua_insert, lua_pushstring(), lua_setupvalue(), LUA_TFUNCTION, luaL_checkinteger(), luaL_checktype(), name, and NULL.

Referenced by db_getupvalue(), and db_setupvalue().

◆ checkstack()

static void checkstack ( lua_State * L,
lua_State * L1,
int n )
static

Definition at line 35 of file lua-5.4.3/src/ldblib.c.

35 {
36 if (l_unlikely(L != L1 && !lua_checkstack(L1, n)))
37 luaL_error(L, "stack overflow");
38}
LUA_API int lua_checkstack(lua_State *L, int size)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)

References lua_checkstack(), and luaL_error().

Referenced by db_gethook(), db_getinfo(), db_getlocal(), db_sethook(), and db_setlocal().

◆ checkupval()

static void * checkupval ( lua_State * L,
int argf,
int argnup,
int * pnup )
static

Definition at line 285 of file lua-5.4.3/src/ldblib.c.

285 {
286 void *id;
287 int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */
288 luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */
289 id = lua_upvalueid(L, argf, nup);
290 if (pnup) {
291 luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index");
292 *pnup = nup;
293 }
294 return id;
295}
#define luaL_argcheck(L, cond, numarg, extramsg)
LUA_API void * lua_upvalueid(lua_State *L, int fidx, int n)

References LUA_TFUNCTION, lua_upvalueid(), luaL_argcheck, luaL_checkinteger(), luaL_checktype(), and NULL.

Referenced by db_upvalueid(), and db_upvaluejoin().

◆ db_debug()

static int db_debug ( lua_State * L)
static

Definition at line 420 of file lua-5.4.3/src/ldblib.c.

420 {
421 for (;;) {
422 char buffer[250];
423 lua_writestringerror("%s", "lua_debug> ");
424 if (fgets(buffer, sizeof(buffer), stdin) == NULL ||
425 strcmp(buffer, "cont\n") == 0)
426 return 0;
427 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
428 lua_pcall(L, 0, 0, 0))
430 lua_settop(L, 0); /* remove eventual returns */
431 }
432}
LUA_API void lua_settop(lua_State *L, int idx)
LUALIB_API const char * luaL_tolstring(lua_State *L, int idx, size_t *len)
#define luaL_loadbuffer(L, s, sz, n)
#define lua_pcall(L, n, r, f)
#define lua_writestringerror(s, p)

References lua_pcall, lua_settop(), lua_writestringerror, luaL_loadbuffer, luaL_tolstring(), and NULL.

◆ db_gethook()

static int db_gethook ( lua_State * L)
static

Definition at line 395 of file lua-5.4.3/src/ldblib.c.

395 {
396 int arg;
397 lua_State *L1 = getthread(L, &arg);
398 char buff[5];
399 int mask = lua_gethookmask(L1);
400 lua_Hook hook = lua_gethook(L1);
401 if (hook == NULL) { /* no hook? */
402 luaL_pushfail(L);
403 return 1;
404 }
405 else if (hook != hookf) /* external hook? */
406 lua_pushliteral(L, "external hook");
407 else { /* hook table must exist */
409 checkstack(L, L1, 1);
410 lua_pushthread(L1); lua_xmove(L1, L, 1);
411 lua_rawget(L, -2); /* 1st result = hooktable[L1] */
412 lua_remove(L, -2); /* remove hook table */
413 }
414 lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */
415 lua_pushinteger(L, lua_gethookcount(L1)); /* 3rd result = count */
416 return 3;
417}
CURL_EXTERN int void * arg
Definition curl.h:2622
LUA_API int lua_pushthread(lua_State *L)
LUA_API void lua_rawget(lua_State *L, int idx)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_xmove(lua_State *from, lua_State *to, int n)
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
LUA_API int lua_gethookmask(lua_State *L)
LUA_API int lua_gethookcount(lua_State *L)
LUA_API lua_Hook lua_gethook(lua_State *L)
#define LUA_REGISTRYINDEX
#define lua_pushliteral(L, s)
void(* lua_Hook)(lua_State *L, lua_Debug *ar)
#define mask(n)
#define lua_remove(L, idx)
#define luaL_pushfail(L)
static lua_State * getthread(lua_State *L, int *arg)
static void hookf(lua_State *L, lua_Debug *ar)
static char * unmakemask(int mask, char *smask)
static void checkstack(lua_State *L, lua_State *L1, int n)
static const char *const HOOKKEY

References arg, checkstack(), getthread(), hookf(), HOOKKEY, lua_getfield(), lua_gethook(), lua_gethookcount(), lua_gethookmask(), lua_pushinteger(), lua_pushliteral, lua_pushstring(), lua_pushthread(), lua_rawget(), LUA_REGISTRYINDEX, lua_remove, lua_xmove(), luaL_pushfail, mask, NULL, and unmakemask().

◆ db_getinfo()

static int db_getinfo ( lua_State * L)
static

Definition at line 149 of file lua-5.4.3/src/ldblib.c.

149 {
150 lua_Debug ar;
151 int arg;
152 lua_State *L1 = getthread(L, &arg);
153 const char *options = luaL_optstring(L, arg+2, "flnSrtu");
154 checkstack(L, L1, 3);
155 luaL_argcheck(L, options[0] != '>', arg + 2, "invalid option '>'");
156 if (lua_isfunction(L, arg + 1)) { /* info about a function? */
157 options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */
158 lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */
159 lua_xmove(L, L1, 1);
160 }
161 else { /* stack level */
162 if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {
163 luaL_pushfail(L); /* level out of range */
164 return 1;
165 }
166 }
167 if (!lua_getinfo(L1, options, &ar))
168 return luaL_argerror(L, arg+2, "invalid option");
169 lua_newtable(L); /* table to collect results */
170 if (strchr(options, 'S')) {
171 lua_pushlstring(L, ar.source, ar.srclen);
172 lua_setfield(L, -2, "source");
173 settabss(L, "short_src", ar.short_src);
174 settabsi(L, "linedefined", ar.linedefined);
175 settabsi(L, "lastlinedefined", ar.lastlinedefined);
176 settabss(L, "what", ar.what);
177 }
178 if (strchr(options, 'l'))
179 settabsi(L, "currentline", ar.currentline);
180 if (strchr(options, 'u')) {
181 settabsi(L, "nups", ar.nups);
182 settabsi(L, "nparams", ar.nparams);
183 settabsb(L, "isvararg", ar.isvararg);
184 }
185 if (strchr(options, 'n')) {
186 settabss(L, "name", ar.name);
187 settabss(L, "namewhat", ar.namewhat);
188 }
189 if (strchr(options, 'r')) {
190 settabsi(L, "ftransfer", ar.ftransfer);
191 settabsi(L, "ntransfer", ar.ntransfer);
192 }
193 if (strchr(options, 't'))
194 settabsb(L, "istailcall", ar.istailcall);
195 if (strchr(options, 'L'))
196 treatstackoption(L, L1, "activelines");
197 if (strchr(options, 'f'))
198 treatstackoption(L, L1, "func");
199 return 1; /* return table */
200}
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
#define luaL_optstring(L, n, d)
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
#define lua_isfunction(L, n)
#define lua_newtable(L)
static void settabsi(lua_State *L, const char *k, int v)
static void treatstackoption(lua_State *L, lua_State *L1, const char *fname)
static void settabss(lua_State *L, const char *k, const char *v)
static void settabsb(lua_State *L, const char *k, int v)
const char * what
unsigned short ntransfer
const char * source
char short_src[LUA_IDSIZE]
const char * name
unsigned short ftransfer
unsigned char nparams
const char * namewhat

References arg, checkstack(), lua_Debug::currentline, lua_Debug::ftransfer, getthread(), lua_Debug::istailcall, lua_Debug::isvararg, lua_Debug::lastlinedefined, lua_Debug::linedefined, lua_getinfo(), lua_getstack(), lua_isfunction, lua_newtable, lua_pushfstring(), lua_pushlstring(), lua_pushvalue(), lua_setfield(), lua_xmove(), luaL_argcheck, luaL_argerror(), luaL_checkinteger(), luaL_optstring, luaL_pushfail, lua_Debug::name, lua_Debug::namewhat, lua_Debug::nparams, lua_Debug::ntransfer, lua_Debug::nups, settabsb(), settabsi(), settabss(), lua_Debug::short_src, lua_Debug::source, lua_Debug::srclen, treatstackoption(), and lua_Debug::what.

◆ db_getlocal()

static int db_getlocal ( lua_State * L)
static

Definition at line 203 of file lua-5.4.3/src/ldblib.c.

203 {
204 int arg;
205 lua_State *L1 = getthread(L, &arg);
206 int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */
207 if (lua_isfunction(L, arg + 1)) { /* function argument? */
208 lua_pushvalue(L, arg + 1); /* push function */
209 lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */
210 return 1; /* return only name (there is no value) */
211 }
212 else { /* stack-level argument */
213 lua_Debug ar;
214 const char *name;
215 int level = (int)luaL_checkinteger(L, arg + 1);
216 if (l_unlikely(!lua_getstack(L1, level, &ar))) /* out of range? */
217 return luaL_argerror(L, arg+1, "level out of range");
218 checkstack(L, L1, 1);
219 name = lua_getlocal(L1, &ar, nvar);
220 if (name) {
221 lua_xmove(L1, L, 1); /* move local value */
222 lua_pushstring(L, name); /* push name */
223 lua_rotate(L, -2, 1); /* re-order */
224 return 2;
225 }
226 else {
227 luaL_pushfail(L); /* no name (nor value) */
228 return 1;
229 }
230 }
231}
LUA_API const char * lua_getlocal(lua_State *L, const lua_Debug *ar, int n)
LUA_API void lua_rotate(lua_State *L, int idx, int n)

References arg, checkstack(), getthread(), lua_getlocal(), lua_getstack(), lua_isfunction, lua_pushstring(), lua_pushvalue(), lua_rotate(), lua_xmove(), luaL_argerror(), luaL_checkinteger(), luaL_pushfail, name, and NULL.

◆ db_getmetatable()

static int db_getmetatable ( lua_State * L)
static

Definition at line 47 of file lua-5.4.3/src/ldblib.c.

47 {
48 luaL_checkany(L, 1);
49 if (!lua_getmetatable(L, 1)) {
50 lua_pushnil(L); /* no metatable */
51 }
52 return 1;
53}
LUA_API void lua_pushnil(lua_State *L)
LUA_API int lua_getmetatable(lua_State *L, int objindex)
LUALIB_API void luaL_checkany(lua_State *L, int narg)

References lua_getmetatable(), lua_pushnil(), and luaL_checkany().

◆ db_getregistry()

static int db_getregistry ( lua_State * L)
static

Definition at line 41 of file lua-5.4.3/src/ldblib.c.

41 {
43 return 1;
44}

References lua_pushvalue(), and LUA_REGISTRYINDEX.

◆ db_getupvalue()

static int db_getupvalue ( lua_State * L)
static

Definition at line 270 of file lua-5.4.3/src/ldblib.c.

270 {
271 return auxupvalue(L, 1);
272}
static int auxupvalue(lua_State *L, int get)

References auxupvalue().

◆ db_getuservalue()

static int db_getuservalue ( lua_State * L)
static

Definition at line 65 of file lua-5.4.3/src/ldblib.c.

65 {
66 int n = (int)luaL_optinteger(L, 2, 1);
67 if (lua_type(L, 1) != LUA_TUSERDATA)
69 else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) {
70 lua_pushboolean(L, 1);
71 return 2;
72 }
73 return 1;
74}
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API int lua_type(lua_State *L, int idx)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
#define LUA_TNONE
#define LUA_TUSERDATA
LUA_API int lua_getiuservalue(lua_State *L, int idx, int n)

References lua_getiuservalue(), lua_pushboolean(), LUA_TNONE, LUA_TUSERDATA, lua_type(), luaL_optinteger(), and luaL_pushfail.

◆ db_setcstacklimit()

static int db_setcstacklimit ( lua_State * L)
static

Definition at line 449 of file lua-5.4.3/src/ldblib.c.

449 {
450 int limit = (int)luaL_checkinteger(L, 1);
451 int res = lua_setcstacklimit(L, limit);
452 lua_pushinteger(L, res);
453 return 1;
454}
LUA_API int lua_setcstacklimit(lua_State *L, unsigned int limit)

References lua_pushinteger(), lua_setcstacklimit(), and luaL_checkinteger().

◆ db_sethook()

static int db_sethook ( lua_State * L)
static

hooktable.__mode = "k"

Definition at line 365 of file lua-5.4.3/src/ldblib.c.

365 {
366 int arg, mask, count;
367 lua_Hook func;
368 lua_State *L1 = getthread(L, &arg);
369 if (lua_isnoneornil(L, arg+1)) { /* no hook? */
370 lua_settop(L, arg+1);
371 func = NULL; mask = 0; count = 0; /* turn off hooks */
372 }
373 else {
374 const char *smask = luaL_checkstring(L, arg+2);
376 count = (int)luaL_optinteger(L, arg + 3, 0);
377 func = hookf; mask = makemask(smask, count);
378 }
380 /* table just created; initialize it */
381 lua_pushliteral(L, "k");
382 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
383 lua_pushvalue(L, -1);
384 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */
385 }
386 checkstack(L, L1, 1);
387 lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */
388 lua_pushvalue(L, arg + 1); /* value (hook function) */
389 lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */
390 lua_sethook(L1, func, mask, count);
391 return 0;
392}
LUA_API int lua_setmetatable(lua_State *L, int objindex)
LUA_API void lua_rawset(lua_State *L, int idx)
#define luaL_checkstring(L, n)
LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
#define lua_isnoneornil(L, n)
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)
static int makemask(const char *smask, int count)

References arg, checkstack(), getthread(), hookf(), HOOKKEY, lua_isnoneornil, lua_pushliteral, lua_pushthread(), lua_pushvalue(), lua_rawset(), LUA_REGISTRYINDEX, lua_setfield(), lua_sethook(), lua_setmetatable(), lua_settop(), LUA_TFUNCTION, lua_xmove(), luaL_checkstring, luaL_checktype(), luaL_getsubtable(), luaL_optinteger(), makemask(), mask, and NULL.

◆ db_setlocal()

static int db_setlocal ( lua_State * L)
static

Definition at line 234 of file lua-5.4.3/src/ldblib.c.

234 {
235 int arg;
236 const char *name;
237 lua_State *L1 = getthread(L, &arg);
238 lua_Debug ar;
239 int level = (int)luaL_checkinteger(L, arg + 1);
240 int nvar = (int)luaL_checkinteger(L, arg + 2);
241 if (l_unlikely(!lua_getstack(L1, level, &ar))) /* out of range? */
242 return luaL_argerror(L, arg+1, "level out of range");
243 luaL_checkany(L, arg+3);
244 lua_settop(L, arg+3);
245 checkstack(L, L1, 1);
246 lua_xmove(L, L1, 1);
247 name = lua_setlocal(L1, &ar, nvar);
248 if (name == NULL)
249 lua_pop(L1, 1); /* pop value (if not popped by 'lua_setlocal') */
251 return 1;
252}
LUA_API const char * lua_setlocal(lua_State *L, const lua_Debug *ar, int n)
#define lua_pop(L, n)

References arg, checkstack(), getthread(), lua_getstack(), lua_pop, lua_pushstring(), lua_setlocal(), lua_settop(), lua_xmove(), luaL_argerror(), luaL_checkany(), luaL_checkinteger(), name, and NULL.

◆ db_setmetatable()

static int db_setmetatable ( lua_State * L)
static

Definition at line 56 of file lua-5.4.3/src/ldblib.c.

56 {
57 int t = lua_type(L, 2);
58 luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");
59 lua_settop(L, 2);
60 lua_setmetatable(L, 1);
61 return 1; /* return 1st argument */
62}
#define LUA_TTABLE
#define LUA_TNIL
#define luaL_argexpected(L, cond, arg, tname)

References lua_setmetatable(), lua_settop(), LUA_TNIL, LUA_TTABLE, lua_type(), and luaL_argexpected.

◆ db_setupvalue()

static int db_setupvalue ( lua_State * L)
static

Definition at line 275 of file lua-5.4.3/src/ldblib.c.

275 {
276 luaL_checkany(L, 3);
277 return auxupvalue(L, 0);
278}

References auxupvalue(), and luaL_checkany().

◆ db_setuservalue()

static int db_setuservalue ( lua_State * L)
static

Definition at line 77 of file lua-5.4.3/src/ldblib.c.

77 {
78 int n = (int)luaL_optinteger(L, 3, 1);
80 luaL_checkany(L, 2);
81 lua_settop(L, 2);
82 if (!lua_setiuservalue(L, 1, n))
84 return 1;
85}
LUA_API int lua_setiuservalue(lua_State *L, int idx, int n)

References lua_setiuservalue(), lua_settop(), LUA_TUSERDATA, luaL_checkany(), luaL_checktype(), luaL_optinteger(), and luaL_pushfail.

◆ db_traceback()

static int db_traceback ( lua_State * L)
static

Definition at line 435 of file lua-5.4.3/src/ldblib.c.

435 {
436 int arg;
437 lua_State *L1 = getthread(L, &arg);
438 const char *msg = lua_tostring(L, arg + 1);
439 if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */
440 lua_pushvalue(L, arg + 1); /* return it untouched */
441 else {
442 int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0);
443 luaL_traceback(L, L1, msg, level);
444 }
445 return 1;
446}
#define lua_tostring(L, i)
LUALIB_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level)

References arg, getthread(), lua_isnoneornil, lua_pushvalue(), lua_tostring, luaL_optinteger(), luaL_traceback(), and NULL.

◆ db_upvalueid()

static int db_upvalueid ( lua_State * L)
static

Definition at line 298 of file lua-5.4.3/src/ldblib.c.

298 {
299 void *id = checkupval(L, 1, 2, NULL);
300 if (id != NULL)
302 else
303 luaL_pushfail(L);
304 return 1;
305}
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
static void * checkupval(lua_State *L, int argf, int argnup, int *pnup)

References checkupval(), lua_pushlightuserdata(), luaL_pushfail, and NULL.

◆ db_upvaluejoin()

static int db_upvaluejoin ( lua_State * L)
static

Definition at line 308 of file lua-5.4.3/src/ldblib.c.

308 {
309 int n1, n2;
310 checkupval(L, 1, 2, &n1);
311 checkupval(L, 3, 4, &n2);
312 luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");
313 luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");
314 lua_upvaluejoin(L, 1, n1, 3, n2);
315 return 0;
316}
LUA_API int lua_iscfunction(lua_State *L, int idx)
LUA_API void lua_upvaluejoin(lua_State *L, int fidx1, int n1, int fidx2, int n2)

References checkupval(), lua_iscfunction(), lua_upvaluejoin(), and luaL_argcheck.

◆ getthread()

static lua_State * getthread ( lua_State * L,
int * arg )
static

Definition at line 94 of file lua-5.4.3/src/ldblib.c.

94 {
95 if (lua_isthread(L, 1)) {
96 *arg = 1;
97 return lua_tothread(L, 1);
98 }
99 else {
100 *arg = 0;
101 return L; /* function will operate over current thread */
102 }
103}
LUA_API lua_State * lua_tothread(lua_State *L, int idx)
#define lua_isthread(L, n)

References arg, lua_isthread, and lua_tothread().

Referenced by db_gethook(), db_getinfo(), db_getlocal(), db_sethook(), db_setlocal(), and db_traceback().

◆ hookf()

static void hookf ( lua_State * L,
lua_Debug * ar )
static

Definition at line 323 of file lua-5.4.3/src/ldblib.c.

323 {
324 static const char *const hooknames[] =
325 {"call", "return", "line", "count", "tail call"};
328 if (lua_rawget(L, -2) == LUA_TFUNCTION) { /* is there a hook function? */
329 lua_pushstring(L, hooknames[(int)ar->event]); /* push event name */
330 if (ar->currentline >= 0)
331 lua_pushinteger(L, ar->currentline); /* push current line */
332 else lua_pushnil(L);
333 lua_assert(lua_getinfo(L, "lS", ar));
334 lua_call(L, 2, 0); /* call hook function */
335 }
336}
#define lua_assert(c)
#define lua_call(L, n, r)

References lua_Debug::currentline, lua_Debug::event, HOOKKEY, lua_assert, lua_call, lua_getfield(), lua_getinfo(), lua_pushinteger(), lua_pushnil(), lua_pushstring(), lua_pushthread(), lua_rawget(), LUA_REGISTRYINDEX, and LUA_TFUNCTION.

Referenced by db_gethook(), and db_sethook().

◆ luaopen_debug()

LUAMOD_API int luaopen_debug ( lua_State * L)

Definition at line 479 of file lua-5.4.3/src/ldblib.c.

479 {
480 luaL_newlib(L, dblib);
481 return 1;
482}
#define luaL_newlib(L, l)
static const luaL_Reg dblib[]

References dblib, and luaL_newlib.

◆ makemask()

static int makemask ( const char * smask,
int count )
static

Definition at line 342 of file lua-5.4.3/src/ldblib.c.

342 {
343 int mask = 0;
344 if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
345 if (strchr(smask, 'r')) mask |= LUA_MASKRET;
346 if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
347 if (count > 0) mask |= LUA_MASKCOUNT;
348 return mask;
349}
#define LUA_MASKCOUNT
#define LUA_MASKCALL
#define LUA_MASKLINE
#define LUA_MASKRET

References LUA_MASKCALL, LUA_MASKCOUNT, LUA_MASKLINE, LUA_MASKRET, and mask.

Referenced by db_sethook().

◆ settabsb()

static void settabsb ( lua_State * L,
const char * k,
int v )
static

Definition at line 121 of file lua-5.4.3/src/ldblib.c.

121 {
122 lua_pushboolean(L, v);
123 lua_setfield(L, -2, k);
124}

References lua_pushboolean(), and lua_setfield().

Referenced by db_getinfo().

◆ settabsi()

static void settabsi ( lua_State * L,
const char * k,
int v )
static

Definition at line 116 of file lua-5.4.3/src/ldblib.c.

116 {
117 lua_pushinteger(L, v);
118 lua_setfield(L, -2, k);
119}

References lua_pushinteger(), and lua_setfield().

Referenced by db_getinfo().

◆ settabss()

static void settabss ( lua_State * L,
const char * k,
const char * v )
static

Definition at line 111 of file lua-5.4.3/src/ldblib.c.

111 {
112 lua_pushstring(L, v);
113 lua_setfield(L, -2, k);
114}

References lua_pushstring(), and lua_setfield().

Referenced by db_getinfo().

◆ treatstackoption()

static void treatstackoption ( lua_State * L,
lua_State * L1,
const char * fname )
static

Definition at line 134 of file lua-5.4.3/src/ldblib.c.

134 {
135 if (L == L1)
136 lua_rotate(L, -2, 1); /* exchange object and table */
137 else
138 lua_xmove(L1, L, 1); /* move object to the "main" stack */
139 lua_setfield(L, -2, fname); /* put object into table */
140}

References lua_rotate(), lua_setfield(), and lua_xmove().

Referenced by db_getinfo().

◆ unmakemask()

static char * unmakemask ( int mask,
char * smask )
static

Definition at line 355 of file lua-5.4.3/src/ldblib.c.

355 {
356 int i = 0;
357 if (mask & LUA_MASKCALL) smask[i++] = 'c';
358 if (mask & LUA_MASKRET) smask[i++] = 'r';
359 if (mask & LUA_MASKLINE) smask[i++] = 'l';
360 smask[i] = '\0';
361 return smask;
362}

References LUA_MASKCALL, LUA_MASKLINE, LUA_MASKRET, and mask.

Referenced by db_gethook().

Variable Documentation

◆ dblib

const luaL_Reg dblib[]
static
Initial value:
= {
{"debug", db_debug},
{"getuservalue", db_getuservalue},
{"gethook", db_gethook},
{"getinfo", db_getinfo},
{"getlocal", db_getlocal},
{"getregistry", db_getregistry},
{"getmetatable", db_getmetatable},
{"getupvalue", db_getupvalue},
{"upvaluejoin", db_upvaluejoin},
{"upvalueid", db_upvalueid},
{"setuservalue", db_setuservalue},
{"sethook", db_sethook},
{"setlocal", db_setlocal},
{"setmetatable", db_setmetatable},
{"setupvalue", db_setupvalue},
{"traceback", db_traceback},
{"setcstacklimit", db_setcstacklimit},
}
static int db_setlocal(lua_State *L)
static int db_getuservalue(lua_State *L)
static int db_setuservalue(lua_State *L)
static int db_setmetatable(lua_State *L)
static int db_getinfo(lua_State *L)
static int db_gethook(lua_State *L)
static int db_getupvalue(lua_State *L)
static int db_getregistry(lua_State *L)
static int db_sethook(lua_State *L)
static int db_getmetatable(lua_State *L)
static int db_setupvalue(lua_State *L)
static int db_upvaluejoin(lua_State *L)
static int db_debug(lua_State *L)
static int db_setcstacklimit(lua_State *L)
static int db_upvalueid(lua_State *L)
static int db_traceback(lua_State *L)
static int db_getlocal(lua_State *L)

Definition at line 457 of file lua-5.4.3/src/ldblib.c.

457 {
458 {"debug", db_debug},
459 {"getuservalue", db_getuservalue},
460 {"gethook", db_gethook},
461 {"getinfo", db_getinfo},
462 {"getlocal", db_getlocal},
463 {"getregistry", db_getregistry},
464 {"getmetatable", db_getmetatable},
465 {"getupvalue", db_getupvalue},
466 {"upvaluejoin", db_upvaluejoin},
467 {"upvalueid", db_upvalueid},
468 {"setuservalue", db_setuservalue},
469 {"sethook", db_sethook},
470 {"setlocal", db_setlocal},
471 {"setmetatable", db_setmetatable},
472 {"setupvalue", db_setupvalue},
473 {"traceback", db_traceback},
474 {"setcstacklimit", db_setcstacklimit},
475 {NULL, NULL}
476};

Referenced by luaopen_debug().

◆ HOOKKEY

const char* const HOOKKEY = "_HOOKKEY"
static

Definition at line 27 of file lua-5.4.3/src/ldblib.c.

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