Lines Matching refs:L

22 static int db_getregistry (lua_State *L) {  in db_getregistry()  argument
23 lua_pushvalue(L, LUA_REGISTRYINDEX); in db_getregistry()
28 static int db_getmetatable (lua_State *L) { in db_getmetatable() argument
29 luaL_checkany(L, 1); in db_getmetatable()
30 if (!lua_getmetatable(L, 1)) { in db_getmetatable()
31 lua_pushnil(L); /* no metatable */ in db_getmetatable()
37 static int db_setmetatable (lua_State *L) { in db_setmetatable() argument
38 int t = lua_type(L, 2); in db_setmetatable()
39 luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, in db_setmetatable()
41 lua_settop(L, 2); in db_setmetatable()
42 lua_pushboolean(L, lua_setmetatable(L, 1)); in db_setmetatable()
47 static int db_getfenv (lua_State *L) { in db_getfenv() argument
48 luaL_checkany(L, 1); in db_getfenv()
49 lua_getfenv(L, 1); in db_getfenv()
54 static int db_setfenv (lua_State *L) { in db_setfenv() argument
55 luaL_checktype(L, 2, LUA_TTABLE); in db_setfenv()
56 lua_settop(L, 2); in db_setfenv()
57 if (lua_setfenv(L, 1) == 0) in db_setfenv()
58 luaL_error(L, LUA_QL("setfenv") in db_setfenv()
64 static void settabss (lua_State *L, const char *i, const char *v) { in settabss() argument
65 lua_pushstring(L, v); in settabss()
66 lua_setfield(L, -2, i); in settabss()
70 static void settabsi (lua_State *L, const char *i, int v) { in settabsi() argument
71 lua_pushinteger(L, v); in settabsi()
72 lua_setfield(L, -2, i); in settabsi()
76 static lua_State *getthread (lua_State *L, int *arg) { in getthread() argument
77 if (lua_isthread(L, 1)) { in getthread()
79 return lua_tothread(L, 1); in getthread()
83 return L; in getthread()
88 static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { in treatstackoption() argument
89 if (L == L1) { in treatstackoption()
90 lua_pushvalue(L, -2); in treatstackoption()
91 lua_remove(L, -3); in treatstackoption()
94 lua_xmove(L1, L, 1); in treatstackoption()
95 lua_setfield(L, -2, fname); in treatstackoption()
99 static int db_getinfo (lua_State *L) { in db_getinfo() argument
102 lua_State *L1 = getthread(L, &arg); in db_getinfo()
103 const char *options = luaL_optstring(L, arg+2, "flnSu"); in db_getinfo()
104 if (lua_isnumber(L, arg+1)) { in db_getinfo()
105 if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { in db_getinfo()
106 lua_pushnil(L); /* level out of range */ in db_getinfo()
110 else if (lua_isfunction(L, arg+1)) { in db_getinfo()
111 lua_pushfstring(L, ">%s", options); in db_getinfo()
112 options = lua_tostring(L, -1); in db_getinfo()
113 lua_pushvalue(L, arg+1); in db_getinfo()
114 lua_xmove(L, L1, 1); in db_getinfo()
117 return luaL_argerror(L, arg+1, "function or level expected"); in db_getinfo()
119 return luaL_argerror(L, arg+2, "invalid option"); in db_getinfo()
120 lua_createtable(L, 0, 2); in db_getinfo()
122 settabss(L, "source", ar.source); in db_getinfo()
123 settabss(L, "short_src", ar.short_src); in db_getinfo()
124 settabsi(L, "linedefined", ar.linedefined); in db_getinfo()
125 settabsi(L, "lastlinedefined", ar.lastlinedefined); in db_getinfo()
126 settabss(L, "what", ar.what); in db_getinfo()
129 settabsi(L, "currentline", ar.currentline); in db_getinfo()
131 settabsi(L, "nups", ar.nups); in db_getinfo()
133 settabss(L, "name", ar.name); in db_getinfo()
134 settabss(L, "namewhat", ar.namewhat); in db_getinfo()
137 treatstackoption(L, L1, "activelines"); in db_getinfo()
139 treatstackoption(L, L1, "func"); in db_getinfo()
144 static int db_getlocal (lua_State *L) { in db_getlocal() argument
146 lua_State *L1 = getthread(L, &arg); in db_getlocal()
149 if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ in db_getlocal()
150 return luaL_argerror(L, arg+1, "level out of range"); in db_getlocal()
151 name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); in db_getlocal()
153 lua_xmove(L1, L, 1); in db_getlocal()
154 lua_pushstring(L, name); in db_getlocal()
155 lua_pushvalue(L, -2); in db_getlocal()
159 lua_pushnil(L); in db_getlocal()
165 static int db_setlocal (lua_State *L) { in db_setlocal() argument
167 lua_State *L1 = getthread(L, &arg); in db_setlocal()
169 if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ in db_setlocal()
170 return luaL_argerror(L, arg+1, "level out of range"); in db_setlocal()
171 luaL_checkany(L, arg+3); in db_setlocal()
172 lua_settop(L, arg+3); in db_setlocal()
173 lua_xmove(L, L1, 1); in db_setlocal()
174 lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); in db_setlocal()
179 static int auxupvalue (lua_State *L, int get) { in auxupvalue() argument
181 int n = luaL_checkint(L, 2); in auxupvalue()
182 luaL_checktype(L, 1, LUA_TFUNCTION); in auxupvalue()
183 if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ in auxupvalue()
184 name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); in auxupvalue()
186 lua_pushstring(L, name); in auxupvalue()
187 lua_insert(L, -(get+1)); in auxupvalue()
192 static int db_getupvalue (lua_State *L) { in db_getupvalue() argument
193 return auxupvalue(L, 1); in db_getupvalue()
197 static int db_setupvalue (lua_State *L) { in db_setupvalue() argument
198 luaL_checkany(L, 3); in db_setupvalue()
199 return auxupvalue(L, 0); in db_setupvalue()
207 static void hookf (lua_State *L, lua_Debug *ar) { in hookf() argument
210 lua_pushlightuserdata(L, (void *)&KEY_HOOK); in hookf()
211 lua_rawget(L, LUA_REGISTRYINDEX); in hookf()
212 lua_pushlightuserdata(L, L); in hookf()
213 lua_rawget(L, -2); in hookf()
214 if (lua_isfunction(L, -1)) { in hookf()
215 lua_pushstring(L, hooknames[(int)ar->event]); in hookf()
217 lua_pushinteger(L, ar->currentline); in hookf()
218 else lua_pushnil(L); in hookf()
219 lua_assert(lua_getinfo(L, "lS", ar)); in hookf()
220 lua_call(L, 2, 0); in hookf()
245 static void gethooktable (lua_State *L) { in gethooktable() argument
246 lua_pushlightuserdata(L, (void *)&KEY_HOOK); in gethooktable()
247 lua_rawget(L, LUA_REGISTRYINDEX); in gethooktable()
248 if (!lua_istable(L, -1)) { in gethooktable()
249 lua_pop(L, 1); in gethooktable()
250 lua_createtable(L, 0, 1); in gethooktable()
251 lua_pushlightuserdata(L, (void *)&KEY_HOOK); in gethooktable()
252 lua_pushvalue(L, -2); in gethooktable()
253 lua_rawset(L, LUA_REGISTRYINDEX); in gethooktable()
258 static int db_sethook (lua_State *L) { in db_sethook() argument
261 lua_State *L1 = getthread(L, &arg); in db_sethook()
262 if (lua_isnoneornil(L, arg+1)) { in db_sethook()
263 lua_settop(L, arg+1); in db_sethook()
267 const char *smask = luaL_checkstring(L, arg+2); in db_sethook()
268 luaL_checktype(L, arg+1, LUA_TFUNCTION); in db_sethook()
269 count = luaL_optint(L, arg+3, 0); in db_sethook()
272 gethooktable(L); in db_sethook()
273 lua_pushlightuserdata(L, L1); in db_sethook()
274 lua_pushvalue(L, arg+1); in db_sethook()
275 lua_rawset(L, -3); /* set new hook */ in db_sethook()
276 lua_pop(L, 1); /* remove hook table */ in db_sethook()
282 static int db_gethook (lua_State *L) { in db_gethook() argument
284 lua_State *L1 = getthread(L, &arg); in db_gethook()
289 lua_pushliteral(L, "external hook"); in db_gethook()
291 gethooktable(L); in db_gethook()
292 lua_pushlightuserdata(L, L1); in db_gethook()
293 lua_rawget(L, -2); /* get hook */ in db_gethook()
294 lua_remove(L, -2); /* remove hook table */ in db_gethook()
296 lua_pushstring(L, unmakemask(mask, buff)); in db_gethook()
297 lua_pushinteger(L, lua_gethookcount(L1)); in db_gethook()
302 static int db_debug (lua_State *L) { in db_debug() argument
309 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || in db_debug()
310 lua_pcall(L, 0, 0, 0)) { in db_debug()
311 fputs(lua_tostring(L, -1), stderr); in db_debug()
314 lua_settop(L, 0); /* remove eventual returns */ in db_debug()
322 static int db_errorfb (lua_State *L) { in db_errorfb() argument
326 lua_State *L1 = getthread(L, &arg); in db_errorfb()
328 if (lua_isnumber(L, arg+2)) { in db_errorfb()
329 level = (int)lua_tointeger(L, arg+2); in db_errorfb()
330 lua_pop(L, 1); in db_errorfb()
333 level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ in db_errorfb()
334 if (lua_gettop(L) == arg) in db_errorfb()
335 lua_pushliteral(L, ""); in db_errorfb()
336 else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ in db_errorfb()
337 else lua_pushliteral(L, "\n"); in db_errorfb()
338 lua_pushliteral(L, "stack traceback:"); in db_errorfb()
345 lua_pushliteral(L, "\n\t..."); /* too many levels */ in db_errorfb()
352 lua_pushliteral(L, "\n\t"); in db_errorfb()
354 lua_pushfstring(L, "%s:", ar.short_src); in db_errorfb()
356 lua_pushfstring(L, "%d:", ar.currentline); in db_errorfb()
358 lua_pushfstring(L, " in function " LUA_QS, ar.name); in db_errorfb()
361 lua_pushfstring(L, " in main chunk"); in db_errorfb()
363 lua_pushliteral(L, " ?"); /* C function or tail call */ in db_errorfb()
365 lua_pushfstring(L, " in function <%s:%d>", in db_errorfb()
368 lua_concat(L, lua_gettop(L) - arg); in db_errorfb()
370 lua_concat(L, lua_gettop(L) - arg); in db_errorfb()
394 LUALIB_API int luaopen_debug (lua_State *L) { in luaopen_debug() argument
395 luaL_register(L, LUA_DBLIBNAME, dblib); in luaopen_debug()