diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-10 09:57:55 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-10 09:57:55 -0300 |
| commit | 533737f26e3f8036d7978e09427ea5ff75aec9df (patch) | |
| tree | 003004a423cf20bc4e1493918760494b0d694f93 /ldblib.c | |
| parent | a41d60e1d1f3a954648884d4ab7fb7e9ccdd52d6 (diff) | |
| download | lua-533737f26e3f8036d7978e09427ea5ff75aec9df.tar.gz lua-533737f26e3f8036d7978e09427ea5ff75aec9df.tar.bz2 lua-533737f26e3f8036d7978e09427ea5ff75aec9df.zip | |
new functions `lua_getfield' and `lua_setfield'
Diffstat (limited to '')
| -rw-r--r-- | ldblib.c | 16 |
1 files changed, 6 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.81 2003/07/07 13:37:08 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.82 2003/10/07 20:13:41 roberto Exp roberto $ |
| 3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -19,16 +19,14 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | static void settabss (lua_State *L, const char *i, const char *v) { | 21 | static void settabss (lua_State *L, const char *i, const char *v) { |
| 22 | lua_pushstring(L, i); | ||
| 23 | lua_pushstring(L, v); | 22 | lua_pushstring(L, v); |
| 24 | lua_rawset(L, -3); | 23 | lua_setfield(L, -2, i); |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | static void settabsi (lua_State *L, const char *i, int v) { | 27 | static void settabsi (lua_State *L, const char *i, int v) { |
| 29 | lua_pushstring(L, i); | ||
| 30 | lua_pushinteger(L, v); | 28 | lua_pushinteger(L, v); |
| 31 | lua_rawset(L, -3); | 29 | lua_setfield(L, -2, i); |
| 32 | } | 30 | } |
| 33 | 31 | ||
| 34 | 32 | ||
| @@ -85,12 +83,11 @@ static int getinfo (lua_State *L) { | |||
| 85 | settabss(L, "namewhat", ar.namewhat); | 83 | settabss(L, "namewhat", ar.namewhat); |
| 86 | break; | 84 | break; |
| 87 | case 'f': | 85 | case 'f': |
| 88 | lua_pushliteral(L, "func"); | ||
| 89 | if (L == L1) | 86 | if (L == L1) |
| 90 | lua_pushvalue(L, -3); | 87 | lua_pushvalue(L, -2); |
| 91 | else | 88 | else |
| 92 | lua_xmove(L1, L, 1); | 89 | lua_xmove(L1, L, 1); |
| 93 | lua_rawset(L, -3); | 90 | lua_setfield(L, -2, "func"); |
| 94 | break; | 91 | break; |
| 95 | } | 92 | } |
| 96 | } | 93 | } |
| @@ -341,9 +338,8 @@ static const luaL_reg dblib[] = { | |||
| 341 | 338 | ||
| 342 | LUALIB_API int luaopen_debug (lua_State *L) { | 339 | LUALIB_API int luaopen_debug (lua_State *L) { |
| 343 | luaL_openlib(L, LUA_DBLIBNAME, dblib, 0); | 340 | luaL_openlib(L, LUA_DBLIBNAME, dblib, 0); |
| 344 | lua_pushliteral(L, "_TRACEBACK"); | ||
| 345 | lua_pushcfunction(L, errorfb); | 341 | lua_pushcfunction(L, errorfb); |
| 346 | lua_settable(L, LUA_GLOBALSINDEX); | 342 | lua_setfield(L, LUA_GLOBALSINDEX, "_TRACEBACK"); |
| 347 | return 1; | 343 | return 1; |
| 348 | } | 344 | } |
| 349 | 345 | ||
