Lines Matching refs:L

35 static void checkstack (lua_State *L, lua_State *L1, int n) {  in checkstack()  argument
36 if (L != L1 && !lua_checkstack(L1, n)) in checkstack()
37 luaL_error(L, "stack overflow"); in checkstack()
41 static int db_getregistry (lua_State *L) { in db_getregistry() argument
42 lua_pushvalue(L, LUA_REGISTRYINDEX); in db_getregistry()
47 static int db_getmetatable (lua_State *L) { in db_getmetatable() argument
48 luaL_checkany(L, 1); in db_getmetatable()
49 if (!lua_getmetatable(L, 1)) { in db_getmetatable()
50 lua_pushnil(L); /* no metatable */ in db_getmetatable()
56 static int db_setmetatable (lua_State *L) { in db_setmetatable() argument
57 int t = lua_type(L, 2); in db_setmetatable()
58 luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); in db_setmetatable()
59 lua_settop(L, 2); in db_setmetatable()
60 lua_setmetatable(L, 1); in db_setmetatable()
65 static int db_getuservalue (lua_State *L) { in db_getuservalue() argument
66 int n = (int)luaL_optinteger(L, 2, 1); in db_getuservalue()
67 if (lua_type(L, 1) != LUA_TUSERDATA) in db_getuservalue()
68 luaL_pushfail(L); in db_getuservalue()
69 else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) { in db_getuservalue()
70 lua_pushboolean(L, 1); in db_getuservalue()
77 static int db_setuservalue (lua_State *L) { in db_setuservalue() argument
78 int n = (int)luaL_optinteger(L, 3, 1); in db_setuservalue()
79 luaL_checktype(L, 1, LUA_TUSERDATA); in db_setuservalue()
80 luaL_checkany(L, 2); in db_setuservalue()
81 lua_settop(L, 2); in db_setuservalue()
82 if (!lua_setiuservalue(L, 1, n)) in db_setuservalue()
83 luaL_pushfail(L); in db_setuservalue()
94 static lua_State *getthread (lua_State *L, int *arg) { in getthread() argument
95 if (lua_isthread(L, 1)) { in getthread()
97 return lua_tothread(L, 1); in getthread()
101 return L; /* function will operate over current thread */ in getthread()
111 static void settabss (lua_State *L, const char *k, const char *v) { in settabss() argument
112 lua_pushstring(L, v); in settabss()
113 lua_setfield(L, -2, k); in settabss()
116 static void settabsi (lua_State *L, const char *k, int v) { in settabsi() argument
117 lua_pushinteger(L, v); in settabsi()
118 lua_setfield(L, -2, k); in settabsi()
121 static void settabsb (lua_State *L, const char *k, int v) { in settabsb() argument
122 lua_pushboolean(L, v); in settabsb()
123 lua_setfield(L, -2, k); in settabsb()
134 static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { in treatstackoption() argument
135 if (L == L1) in treatstackoption()
136 lua_rotate(L, -2, 1); /* exchange object and table */ in treatstackoption()
138 lua_xmove(L1, L, 1); /* move object to the "main" stack */ in treatstackoption()
139 lua_setfield(L, -2, fname); /* put object into table */ in treatstackoption()
149 static int db_getinfo (lua_State *L) { in db_getinfo() argument
152 lua_State *L1 = getthread(L, &arg); in db_getinfo()
153 const char *options = luaL_optstring(L, arg+2, "flnSrtu"); in db_getinfo()
154 checkstack(L, L1, 3); in db_getinfo()
155 if (lua_isfunction(L, arg + 1)) { /* info about a function? */ in db_getinfo()
156 options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */ in db_getinfo()
157 lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */ in db_getinfo()
158 lua_xmove(L, L1, 1); in db_getinfo()
161 if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { in db_getinfo()
162 luaL_pushfail(L); /* level out of range */ in db_getinfo()
167 return luaL_argerror(L, arg+2, "invalid option"); in db_getinfo()
168 lua_newtable(L); /* table to collect results */ in db_getinfo()
170 lua_pushlstring(L, ar.source, ar.srclen); in db_getinfo()
171 lua_setfield(L, -2, "source"); in db_getinfo()
172 settabss(L, "short_src", ar.short_src); in db_getinfo()
173 settabsi(L, "linedefined", ar.linedefined); in db_getinfo()
174 settabsi(L, "lastlinedefined", ar.lastlinedefined); in db_getinfo()
175 settabss(L, "what", ar.what); in db_getinfo()
178 settabsi(L, "currentline", ar.currentline); in db_getinfo()
180 settabsi(L, "nups", ar.nups); in db_getinfo()
181 settabsi(L, "nparams", ar.nparams); in db_getinfo()
182 settabsb(L, "isvararg", ar.isvararg); in db_getinfo()
185 settabss(L, "name", ar.name); in db_getinfo()
186 settabss(L, "namewhat", ar.namewhat); in db_getinfo()
189 settabsi(L, "ftransfer", ar.ftransfer); in db_getinfo()
190 settabsi(L, "ntransfer", ar.ntransfer); in db_getinfo()
193 settabsb(L, "istailcall", ar.istailcall); in db_getinfo()
195 treatstackoption(L, L1, "activelines"); in db_getinfo()
197 treatstackoption(L, L1, "func"); in db_getinfo()
202 static int db_getlocal (lua_State *L) { in db_getlocal() argument
204 lua_State *L1 = getthread(L, &arg); in db_getlocal()
205 int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */ in db_getlocal()
206 if (lua_isfunction(L, arg + 1)) { /* function argument? */ in db_getlocal()
207 lua_pushvalue(L, arg + 1); /* push function */ in db_getlocal()
208 lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */ in db_getlocal()
214 int level = (int)luaL_checkinteger(L, arg + 1); in db_getlocal()
216 return luaL_argerror(L, arg+1, "level out of range"); in db_getlocal()
217 checkstack(L, L1, 1); in db_getlocal()
220 lua_xmove(L1, L, 1); /* move local value */ in db_getlocal()
221 lua_pushstring(L, name); /* push name */ in db_getlocal()
222 lua_rotate(L, -2, 1); /* re-order */ in db_getlocal()
226 luaL_pushfail(L); /* no name (nor value) */ in db_getlocal()
233 static int db_setlocal (lua_State *L) { in db_setlocal() argument
236 lua_State *L1 = getthread(L, &arg); in db_setlocal()
238 int level = (int)luaL_checkinteger(L, arg + 1); in db_setlocal()
239 int nvar = (int)luaL_checkinteger(L, arg + 2); in db_setlocal()
241 return luaL_argerror(L, arg+1, "level out of range"); in db_setlocal()
242 luaL_checkany(L, arg+3); in db_setlocal()
243 lua_settop(L, arg+3); in db_setlocal()
244 checkstack(L, L1, 1); in db_setlocal()
245 lua_xmove(L, L1, 1); in db_setlocal()
249 lua_pushstring(L, name); in db_setlocal()
257 static int auxupvalue (lua_State *L, int get) { in auxupvalue() argument
259 int n = (int)luaL_checkinteger(L, 2); /* upvalue index */ in auxupvalue()
260 luaL_checktype(L, 1, LUA_TFUNCTION); /* closure */ in auxupvalue()
261 name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); in auxupvalue()
263 lua_pushstring(L, name); in auxupvalue()
264 lua_insert(L, -(get+1)); /* no-op if get is false */ in auxupvalue()
269 static int db_getupvalue (lua_State *L) { in db_getupvalue() argument
270 return auxupvalue(L, 1); in db_getupvalue()
274 static int db_setupvalue (lua_State *L) { in db_setupvalue() argument
275 luaL_checkany(L, 3); in db_setupvalue()
276 return auxupvalue(L, 0); in db_setupvalue()
284 static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) { in checkupval() argument
286 int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */ in checkupval()
287 luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ in checkupval()
288 id = lua_upvalueid(L, argf, nup); in checkupval()
290 luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index"); in checkupval()
297 static int db_upvalueid (lua_State *L) { in db_upvalueid() argument
298 void *id = checkupval(L, 1, 2, NULL); in db_upvalueid()
300 lua_pushlightuserdata(L, id); in db_upvalueid()
302 luaL_pushfail(L); in db_upvalueid()
307 static int db_upvaluejoin (lua_State *L) { in db_upvaluejoin() argument
309 checkupval(L, 1, 2, &n1); in db_upvaluejoin()
310 checkupval(L, 3, 4, &n2); in db_upvaluejoin()
311 luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); in db_upvaluejoin()
312 luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); in db_upvaluejoin()
313 lua_upvaluejoin(L, 1, n1, 3, n2); in db_upvaluejoin()
322 static void hookf (lua_State *L, lua_Debug *ar) { in hookf() argument
325 lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY); in hookf()
326 lua_pushthread(L); in hookf()
327 if (lua_rawget(L, -2) == LUA_TFUNCTION) { /* is there a hook function? */ in hookf()
328 lua_pushstring(L, hooknames[(int)ar->event]); /* push event name */ in hookf()
330 lua_pushinteger(L, ar->currentline); /* push current line */ in hookf()
331 else lua_pushnil(L); in hookf()
332 lua_assert(lua_getinfo(L, "lS", ar)); in hookf()
333 lua_call(L, 2, 0); /* call hook function */ in hookf()
364 static int db_sethook (lua_State *L) { in db_sethook() argument
367 lua_State *L1 = getthread(L, &arg); in db_sethook()
368 if (lua_isnoneornil(L, arg+1)) { /* no hook? */ in db_sethook()
369 lua_settop(L, arg+1); in db_sethook()
373 const char *smask = luaL_checkstring(L, arg+2); in db_sethook()
374 luaL_checktype(L, arg+1, LUA_TFUNCTION); in db_sethook()
375 count = (int)luaL_optinteger(L, arg + 3, 0); in db_sethook()
378 if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) { in db_sethook()
380 lua_pushstring(L, "k"); in db_sethook()
381 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */ in db_sethook()
382 lua_pushvalue(L, -1); in db_sethook()
383 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */ in db_sethook()
385 checkstack(L, L1, 1); in db_sethook()
386 lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */ in db_sethook()
387 lua_pushvalue(L, arg + 1); /* value (hook function) */ in db_sethook()
388 lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */ in db_sethook()
394 static int db_gethook (lua_State *L) { in db_gethook() argument
396 lua_State *L1 = getthread(L, &arg); in db_gethook()
401 luaL_pushfail(L); in db_gethook()
405 lua_pushliteral(L, "external hook"); in db_gethook()
407 lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY); in db_gethook()
408 checkstack(L, L1, 1); in db_gethook()
409 lua_pushthread(L1); lua_xmove(L1, L, 1); in db_gethook()
410 lua_rawget(L, -2); /* 1st result = hooktable[L1] */ in db_gethook()
411 lua_remove(L, -2); /* remove hook table */ in db_gethook()
413 lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */ in db_gethook()
414 lua_pushinteger(L, lua_gethookcount(L1)); /* 3rd result = count */ in db_gethook()
419 static int db_debug (lua_State *L) { in db_debug() argument
426 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || in db_debug()
427 lua_pcall(L, 0, 0, 0)) in db_debug()
428 lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL)); in db_debug()
429 lua_settop(L, 0); /* remove eventual returns */ in db_debug()
434 static int db_traceback (lua_State *L) { in db_traceback() argument
436 lua_State *L1 = getthread(L, &arg); in db_traceback()
437 const char *msg = lua_tostring(L, arg + 1); in db_traceback()
438 if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */ in db_traceback()
439 lua_pushvalue(L, arg + 1); /* return it untouched */ in db_traceback()
441 int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0); in db_traceback()
442 luaL_traceback(L, L1, msg, level); in db_traceback()
448 static int db_setcstacklimit (lua_State *L) { in db_setcstacklimit() argument
449 int limit = (int)luaL_checkinteger(L, 1); in db_setcstacklimit()
450 int res = lua_setcstacklimit(L, limit); in db_setcstacklimit()
451 lua_pushinteger(L, res); in db_setcstacklimit()
478 LUAMOD_API int luaopen_debug (lua_State *L) { in luaopen_debug() argument
479 luaL_newlib(L, dblib); in luaopen_debug()