Lines Matching full:l
31 ** If L1 != L, L1 can be in any state, and therefore there are no
35 static void checkstack (lua_State *L, lua_State *L1, int n) { in checkstack() argument
36 if (l_unlikely(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 luaL_argcheck(L, options[0] != '>', arg + 2, "invalid option '>'"); in db_getinfo()
156 if (lua_isfunction(L, arg + 1)) { /* info about a function? */ in db_getinfo()
157 options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */ in db_getinfo()
158 lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */ in db_getinfo()
159 lua_xmove(L, L1, 1); in db_getinfo()
162 if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { in db_getinfo()
163 luaL_pushfail(L); /* level out of range */ in db_getinfo()
168 return luaL_argerror(L, arg+2, "invalid option"); in db_getinfo()
169 lua_newtable(L); /* table to collect results */ in db_getinfo()
171 lua_pushlstring(L, ar.source, ar.srclen); in db_getinfo()
172 lua_setfield(L, -2, "source"); in db_getinfo()
173 settabss(L, "short_src", ar.short_src); in db_getinfo()
174 settabsi(L, "linedefined", ar.linedefined); in db_getinfo()
175 settabsi(L, "lastlinedefined", ar.lastlinedefined); in db_getinfo()
176 settabss(L, "what", ar.what); in db_getinfo()
178 if (strchr(options, 'l')) in db_getinfo()
179 settabsi(L, "currentline", ar.currentline); in db_getinfo()
181 settabsi(L, "nups", ar.nups); in db_getinfo()
182 settabsi(L, "nparams", ar.nparams); in db_getinfo()
183 settabsb(L, "isvararg", ar.isvararg); in db_getinfo()
186 settabss(L, "name", ar.name); in db_getinfo()
187 settabss(L, "namewhat", ar.namewhat); in db_getinfo()
190 settabsi(L, "ftransfer", ar.ftransfer); in db_getinfo()
191 settabsi(L, "ntransfer", ar.ntransfer); in db_getinfo()
194 settabsb(L, "istailcall", ar.istailcall); in db_getinfo()
195 if (strchr(options, 'L')) in db_getinfo()
196 treatstackoption(L, L1, "activelines"); in db_getinfo()
198 treatstackoption(L, L1, "func"); in db_getinfo()
203 static int db_getlocal (lua_State *L) { in db_getlocal() argument
205 lua_State *L1 = getthread(L, &arg); in db_getlocal()
206 int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */ in db_getlocal()
207 if (lua_isfunction(L, arg + 1)) { /* function argument? */ in db_getlocal()
208 lua_pushvalue(L, arg + 1); /* push function */ in db_getlocal()
209 lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */ in db_getlocal()
215 int level = (int)luaL_checkinteger(L, arg + 1); in db_getlocal()
217 return luaL_argerror(L, arg+1, "level out of range"); in db_getlocal()
218 checkstack(L, L1, 1); in db_getlocal()
221 lua_xmove(L1, L, 1); /* move local value */ in db_getlocal()
222 lua_pushstring(L, name); /* push name */ in db_getlocal()
223 lua_rotate(L, -2, 1); /* re-order */ in db_getlocal()
227 luaL_pushfail(L); /* no name (nor value) */ in db_getlocal()
234 static int db_setlocal (lua_State *L) { in db_setlocal() argument
237 lua_State *L1 = getthread(L, &arg); in db_setlocal()
239 int level = (int)luaL_checkinteger(L, arg + 1); in db_setlocal()
240 int nvar = (int)luaL_checkinteger(L, arg + 2); in db_setlocal()
242 return luaL_argerror(L, arg+1, "level out of range"); in db_setlocal()
243 luaL_checkany(L, arg+3); in db_setlocal()
244 lua_settop(L, arg+3); in db_setlocal()
245 checkstack(L, L1, 1); in db_setlocal()
246 lua_xmove(L, L1, 1); in db_setlocal()
250 lua_pushstring(L, name); in db_setlocal()
258 static int auxupvalue (lua_State *L, int get) { in auxupvalue() argument
260 int n = (int)luaL_checkinteger(L, 2); /* upvalue index */ in auxupvalue()
261 luaL_checktype(L, 1, LUA_TFUNCTION); /* closure */ in auxupvalue()
262 name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); in auxupvalue()
264 lua_pushstring(L, name); in auxupvalue()
265 lua_insert(L, -(get+1)); /* no-op if get is false */ in auxupvalue()
270 static int db_getupvalue (lua_State *L) { in db_getupvalue() argument
271 return auxupvalue(L, 1); in db_getupvalue()
275 static int db_setupvalue (lua_State *L) { in db_setupvalue() argument
276 luaL_checkany(L, 3); in db_setupvalue()
277 return auxupvalue(L, 0); in db_setupvalue()
285 static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) { in checkupval() argument
287 int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */ in checkupval()
288 luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ in checkupval()
289 id = lua_upvalueid(L, argf, nup); in checkupval()
291 luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index"); in checkupval()
298 static int db_upvalueid (lua_State *L) { in db_upvalueid() argument
299 void *id = checkupval(L, 1, 2, NULL); in db_upvalueid()
301 lua_pushlightuserdata(L, id); in db_upvalueid()
303 luaL_pushfail(L); in db_upvalueid()
308 static int db_upvaluejoin (lua_State *L) { in db_upvaluejoin() argument
310 checkupval(L, 1, 2, &n1); in db_upvaluejoin()
311 checkupval(L, 3, 4, &n2); in db_upvaluejoin()
312 luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); in db_upvaluejoin()
313 luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); in db_upvaluejoin()
314 lua_upvaluejoin(L, 1, n1, 3, n2); in db_upvaluejoin()
323 static void hookf (lua_State *L, lua_Debug *ar) { in hookf() argument
326 lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY); in hookf()
327 lua_pushthread(L); in hookf()
328 if (lua_rawget(L, -2) == LUA_TFUNCTION) { /* is there a hook function? */ in hookf()
329 lua_pushstring(L, hooknames[(int)ar->event]); /* push event name */ in hookf()
331 lua_pushinteger(L, ar->currentline); /* push current line */ in hookf()
332 else lua_pushnil(L); in hookf()
333 lua_assert(lua_getinfo(L, "lS", ar)); in hookf()
334 lua_call(L, 2, 0); /* call hook function */ in hookf()
346 if (strchr(smask, 'l')) mask |= LUA_MASKLINE; in makemask()
359 if (mask & LUA_MASKLINE) smask[i++] = 'l'; in unmakemask()
365 static int db_sethook (lua_State *L) { in db_sethook() argument
368 lua_State *L1 = getthread(L, &arg); in db_sethook()
369 if (lua_isnoneornil(L, arg+1)) { /* no hook? */ in db_sethook()
370 lua_settop(L, arg+1); in db_sethook()
374 const char *smask = luaL_checkstring(L, arg+2); in db_sethook()
375 luaL_checktype(L, arg+1, LUA_TFUNCTION); in db_sethook()
376 count = (int)luaL_optinteger(L, arg + 3, 0); in db_sethook()
379 if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) { in db_sethook()
381 lua_pushliteral(L, "k"); in db_sethook()
382 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */ in db_sethook()
383 lua_pushvalue(L, -1); in db_sethook()
384 lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */ in db_sethook()
386 checkstack(L, L1, 1); in db_sethook()
387 lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */ in db_sethook()
388 lua_pushvalue(L, arg + 1); /* value (hook function) */ in db_sethook()
389 lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */ in db_sethook()
395 static int db_gethook (lua_State *L) { in db_gethook() argument
397 lua_State *L1 = getthread(L, &arg); in db_gethook()
402 luaL_pushfail(L); in db_gethook()
406 lua_pushliteral(L, "external hook"); in db_gethook()
408 lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY); in db_gethook()
409 checkstack(L, L1, 1); in db_gethook()
410 lua_pushthread(L1); lua_xmove(L1, L, 1); in db_gethook()
411 lua_rawget(L, -2); /* 1st result = hooktable[L1] */ in db_gethook()
412 lua_remove(L, -2); /* remove hook table */ in db_gethook()
414 lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */ in db_gethook()
415 lua_pushinteger(L, lua_gethookcount(L1)); /* 3rd result = count */ in db_gethook()
420 static int db_debug (lua_State *L) { in db_debug() argument
427 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || in db_debug()
428 lua_pcall(L, 0, 0, 0)) in db_debug()
429 lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL)); in db_debug()
430 lua_settop(L, 0); /* remove eventual returns */ in db_debug()
435 static int db_traceback (lua_State *L) { in db_traceback() argument
437 lua_State *L1 = getthread(L, &arg); in db_traceback()
438 const char *msg = lua_tostring(L, arg + 1); in db_traceback()
439 if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */ in db_traceback()
440 lua_pushvalue(L, arg + 1); /* return it untouched */ in db_traceback()
442 int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0); in db_traceback()
443 luaL_traceback(L, L1, msg, level); in db_traceback()
449 static int db_setcstacklimit (lua_State *L) { in db_setcstacklimit() argument
450 int limit = (int)luaL_checkinteger(L, 1); in db_setcstacklimit()
451 int res = lua_setcstacklimit(L, limit); in db_setcstacklimit()
452 lua_pushinteger(L, res); in db_setcstacklimit()
479 LUAMOD_API int luaopen_debug (lua_State *L) { in luaopen_debug() argument
480 luaL_newlib(L, dblib); in luaopen_debug()