Lines Matching refs:L
39 static void checkstack (lua_State *L, lua_State *L1, int n) { in checkstack() argument
40 if (l_unlikely(L != L1 && !lua_checkstack(L1, n))) in checkstack()
41 luaL_error(L, "stack overflow"); in checkstack()
45 static int db_getregistry (lua_State *L) { in db_getregistry() argument
46 lua_pushvalue(L, LUA_REGISTRYINDEX); in db_getregistry()
51 static int db_getmetatable (lua_State *L) { in db_getmetatable() argument
52 luaL_checkany(L, 1); in db_getmetatable()
53 if (!lua_getmetatable(L, 1)) { in db_getmetatable()
54 lua_pushnil(L); /* no metatable */ in db_getmetatable()
60 static int db_setmetatable (lua_State *L) { in db_setmetatable() argument
61 int t = lua_type(L, 2); in db_setmetatable()
62 luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); in db_setmetatable()
63 lua_settop(L, 2); in db_setmetatable()
64 lua_setmetatable(L, 1); in db_setmetatable()
69 static int db_getuservalue (lua_State *L) { in db_getuservalue() argument
70 int n = (int)luaL_optinteger(L, 2, 1); in db_getuservalue()
71 if (lua_type(L, 1) != LUA_TUSERDATA) in db_getuservalue()
72 luaL_pushfail(L); in db_getuservalue()
73 else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) { in db_getuservalue()
74 lua_pushboolean(L, 1); in db_getuservalue()
81 static int db_setuservalue (lua_State *L) { in db_setuservalue() argument
82 int n = (int)luaL_optinteger(L, 3, 1); in db_setuservalue()
83 luaL_checktype(L, 1, LUA_TUSERDATA); in db_setuservalue()
84 luaL_checkany(L, 2); in db_setuservalue()
85 lua_settop(L, 2); in db_setuservalue()
86 if (!lua_setiuservalue(L, 1, n)) in db_setuservalue()
87 luaL_pushfail(L); in db_setuservalue()
98 static lua_State *getthread (lua_State *L, int *arg) { in getthread() argument
99 if (lua_isthread(L, 1)) { in getthread()
101 return lua_tothread(L, 1); in getthread()
105 return L; /* function will operate over current thread */ in getthread()
115 static void settabss (lua_State *L, const char *k, const char *v) { in settabss() argument
116 lua_pushstring(L, v); in settabss()
117 lua_setfield(L, -2, k); in settabss()
120 static void settabsi (lua_State *L, const char *k, int v) { in settabsi() argument
121 lua_pushinteger(L, v); in settabsi()
122 lua_setfield(L, -2, k); in settabsi()
125 static void settabsb (lua_State *L, const char *k, int v) { in settabsb() argument
126 lua_pushboolean(L, v); in settabsb()
127 lua_setfield(L, -2, k); in settabsb()
138 static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { in treatstackoption() argument
139 if (L == L1) in treatstackoption()
140 lua_rotate(L, -2, 1); /* exchange object and table */ in treatstackoption()
142 lua_xmove(L1, L, 1); /* move object to the "main" stack */ in treatstackoption()
143 lua_setfield(L, -2, fname); /* put object into table */ in treatstackoption()
153 static int db_getinfo (lua_State *L) { in db_getinfo() argument
156 lua_State *L1 = getthread(L, &arg); in db_getinfo()
157 const char *options = luaL_optstring(L, arg+2, "flnSrtu"); in db_getinfo()
158 checkstack(L, L1, 3); in db_getinfo()
159 luaL_argcheck(L, options[0] != '>', arg + 2, "invalid option '>'"); in db_getinfo()
160 if (lua_isfunction(L, arg + 1)) { /* info about a function? */ in db_getinfo()
161 options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */ in db_getinfo()
162 lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */ in db_getinfo()
163 lua_xmove(L, L1, 1); in db_getinfo()
166 if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { in db_getinfo()
167 luaL_pushfail(L); /* level out of range */ in db_getinfo()
172 return luaL_argerror(L, arg+2, "invalid option"); in db_getinfo()
173 lua_newtable(L); /* table to collect results */ in db_getinfo()
175 lua_pushlstring(L, ar.source, ar.srclen); in db_getinfo()
176 lua_setfield(L, -2, "source"); in db_getinfo()
177 settabss(L, "short_src", ar.short_src); in db_getinfo()
178 settabsi(L, "linedefined", ar.linedefined); in db_getinfo()
179 settabsi(L, "lastlinedefined", ar.lastlinedefined); in db_getinfo()
180 settabss(L, "what", ar.what); in db_getinfo()
183 settabsi(L, "currentline", ar.currentline); in db_getinfo()
185 settabsi(L, "nups", ar.nups); in db_getinfo()
186 settabsi(L, "nparams", ar.nparams); in db_getinfo()
187 settabsb(L, "isvararg", ar.isvararg); in db_getinfo()
190 settabss(L, "name", ar.name); in db_getinfo()
191 settabss(L, "namewhat", ar.namewhat); in db_getinfo()
194 settabsi(L, "ftransfer", ar.ftransfer); in db_getinfo()
195 settabsi(L, "ntransfer", ar.ntransfer); in db_getinfo()
198 settabsb(L, "istailcall", ar.istailcall); in db_getinfo()
200 treatstackoption(L, L1, "activelines"); in db_getinfo()
202 treatstackoption(L, L1, "func"); in db_getinfo()
207 static int db_getlocal (lua_State *L) { in db_getlocal() argument
209 lua_State *L1 = getthread(L, &arg); in db_getlocal()
210 int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */ in db_getlocal()
211 if (lua_isfunction(L, arg + 1)) { /* function argument? */ in db_getlocal()
212 lua_pushvalue(L, arg + 1); /* push function */ in db_getlocal()
213 lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */ in db_getlocal()
219 int level = (int)luaL_checkinteger(L, arg + 1); in db_getlocal()
221 return luaL_argerror(L, arg+1, "level out of range"); in db_getlocal()
222 checkstack(L, L1, 1); in db_getlocal()
225 lua_xmove(L1, L, 1); /* move local value */ in db_getlocal()
226 lua_pushstring(L, name); /* push name */ in db_getlocal()
227 lua_rotate(L, -2, 1); /* re-order */ in db_getlocal()
231 luaL_pushfail(L); /* no name (nor value) */ in db_getlocal()
238 static int db_setlocal (lua_State *L) { in db_setlocal() argument
241 lua_State *L1 = getthread(L, &arg); in db_setlocal()
243 int level = (int)luaL_checkinteger(L, arg + 1); in db_setlocal()
244 int nvar = (int)luaL_checkinteger(L, arg + 2); in db_setlocal()
246 return luaL_argerror(L, arg+1, "level out of range"); in db_setlocal()
247 luaL_checkany(L, arg+3); in db_setlocal()
248 lua_settop(L, arg+3); in db_setlocal()
249 checkstack(L, L1, 1); in db_setlocal()
250 lua_xmove(L, L1, 1); in db_setlocal()
254 lua_pushstring(L, name); in db_setlocal()
262 static int auxupvalue (lua_State *L, int get) { in auxupvalue() argument
264 int n = (int)luaL_checkinteger(L, 2); /* upvalue index */ in auxupvalue()
265 luaL_checktype(L, 1, LUA_TFUNCTION); /* closure */ in auxupvalue()
266 name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); in auxupvalue()
268 lua_pushstring(L, name); in auxupvalue()
269 lua_insert(L, -(get+1)); /* no-op if get is false */ in auxupvalue()
274 static int db_getupvalue (lua_State *L) { in db_getupvalue() argument
275 return auxupvalue(L, 1); in db_getupvalue()
279 static int db_setupvalue (lua_State *L) { in db_setupvalue() argument
280 luaL_checkany(L, 3); in db_setupvalue()
281 return auxupvalue(L, 0); in db_setupvalue()
289 static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) { in checkupval() argument
291 int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */ in checkupval()
292 luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ in checkupval()
293 id = lua_upvalueid(L, argf, nup); in checkupval()
295 luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index"); in checkupval()
302 static int db_upvalueid (lua_State *L) { in db_upvalueid() argument
303 void *id = checkupval(L, 1, 2, NULL); in db_upvalueid()
305 lua_pushlightuserdata(L, id); in db_upvalueid()
307 luaL_pushfail(L); in db_upvalueid()
312 static int db_upvaluejoin (lua_State *L) { in db_upvaluejoin() argument
314 checkupval(L, 1, 2, &n1); in db_upvaluejoin()
315 checkupval(L, 3, 4, &n2); in db_upvaluejoin()
316 luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); in db_upvaluejoin()
317 luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); in db_upvaluejoin()
318 lua_upvaluejoin(L, 1, n1, 3, n2); in db_upvaluejoin()
327 static void hookf (lua_State *L, lua_Debug *ar) { in hookf() argument
330 lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY); in hookf()
331 lua_pushthread(L); in hookf()
332 if (lua_rawget(L, -2) == LUA_TFUNCTION) { /* is there a hook function? */ in hookf()
333 lua_pushstring(L, hooknames[(int)ar->event]); /* push event name */ in hookf()
335 lua_pushinteger(L, ar->currentline); /* push current line */ in hookf()
336 else lua_pushnil(L); in hookf()
337 lua_assert(lua_getinfo(L, "lS", ar)); in hookf()
338 lua_call(L, 2, 0); /* call hook function */ in hookf()
369 static int db_sethook (lua_State *L) { in db_sethook() argument
372 lua_State *L1 = getthread(L, &arg); in db_sethook()
373 if (lua_isnoneornil(L, arg+1)) { /* no hook? */ in db_sethook()
374 lua_settop(L, arg+1); in db_sethook()
378 const char *smask = luaL_checkstring(L, arg+2); in db_sethook()
379 luaL_checktype(L, arg+1, LUA_TFUNCTION); in db_sethook()
380 count = (int)luaL_optinteger(L, arg + 3, 0); in db_sethook()
383 if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) { in db_sethook()
385 lua_pushliteral(L, "k"); in db_sethook()
386 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */ in db_sethook()
387 lua_pushvalue(L, -1); in db_sethook()
388 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */ in db_sethook()
390 checkstack(L, L1, 1); in db_sethook()
391 lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */ in db_sethook()
392 lua_pushvalue(L, arg + 1); /* value (hook function) */ in db_sethook()
393 lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */ in db_sethook()
399 static int db_gethook (lua_State *L) { in db_gethook() argument
401 lua_State *L1 = getthread(L, &arg); in db_gethook()
406 luaL_pushfail(L); in db_gethook()
410 lua_pushliteral(L, "external hook"); in db_gethook()
412 lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY); in db_gethook()
413 checkstack(L, L1, 1); in db_gethook()
414 lua_pushthread(L1); lua_xmove(L1, L, 1); in db_gethook()
415 lua_rawget(L, -2); /* 1st result = hooktable[L1] */ in db_gethook()
416 lua_remove(L, -2); /* remove hook table */ in db_gethook()
418 lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */ in db_gethook()
419 lua_pushinteger(L, lua_gethookcount(L1)); /* 3rd result = count */ in db_gethook()
425 static int db_debug (lua_State *L) { in db_debug() argument
432 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || in db_debug()
433 lua_pcall(L, 0, 0, 0)) in db_debug()
434 lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL)); in db_debug()
435 lua_settop(L, 0); /* remove eventual returns */ in db_debug()
441 static int db_traceback (lua_State *L) { in db_traceback() argument
443 lua_State *L1 = getthread(L, &arg); in db_traceback()
444 const char *msg = lua_tostring(L, arg + 1); in db_traceback()
445 if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */ in db_traceback()
446 lua_pushvalue(L, arg + 1); /* return it untouched */ in db_traceback()
448 int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0); in db_traceback()
449 luaL_traceback(L, L1, msg, level); in db_traceback()
455 static int db_setcstacklimit (lua_State *L) { in db_setcstacklimit() argument
456 int limit = (int)luaL_checkinteger(L, 1); in db_setcstacklimit()
457 int res = lua_setcstacklimit(L, limit); in db_setcstacklimit()
458 lua_pushinteger(L, res); in db_setcstacklimit()
487 LUAMOD_API int luaopen_debug (lua_State *L) { in luaopen_debug() argument
488 luaL_newlib(L, dblib); in luaopen_debug()