diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-01-10 13:51:42 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-01-10 13:51:42 -0200 |
| commit | a10d495b18932d59cf00798578eebe071c66c7c4 (patch) | |
| tree | 572bcdde61565a39b7f6b9f23cbb88f12dcbc7e8 | |
| parent | c2e3cc4c89ccd058c84e1d14499c8b26d99c5b3d (diff) | |
| download | lua-a10d495b18932d59cf00798578eebe071c66c7c4.tar.gz lua-a10d495b18932d59cf00798578eebe071c66c7c4.tar.bz2 lua-a10d495b18932d59cf00798578eebe071c66c7c4.zip | |
'luaL_findtable' returns boolean about whether it created a new
table (to easy initializing table)
| -rw-r--r-- | lauxlib.c | 7 | ||||
| -rw-r--r-- | lauxlib.h | 4 |
2 files changed, 6 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.226 2010/11/10 17:38:10 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.227 2010/11/10 18:05:36 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -795,15 +795,16 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { | |||
| 795 | ** ensure that stack[idx][fname] has a table and push that table | 795 | ** ensure that stack[idx][fname] has a table and push that table |
| 796 | ** into the stack | 796 | ** into the stack |
| 797 | */ | 797 | */ |
| 798 | LUALIB_API void luaL_findtable (lua_State *L, int idx, const char *fname) { | 798 | LUALIB_API int luaL_findtable (lua_State *L, int idx, const char *fname) { |
| 799 | lua_getfield(L, idx, fname); | 799 | lua_getfield(L, idx, fname); |
| 800 | if (lua_istable(L, -1)) return; /* table already there */ | 800 | if (lua_istable(L, -1)) return 1; /* table already there */ |
| 801 | else { | 801 | else { |
| 802 | idx = lua_absindex(L, idx); | 802 | idx = lua_absindex(L, idx); |
| 803 | lua_pop(L, 1); /* remove previous result */ | 803 | lua_pop(L, 1); /* remove previous result */ |
| 804 | lua_newtable(L); | 804 | lua_newtable(L); |
| 805 | lua_pushvalue(L, -1); /* copy to be left at top */ | 805 | lua_pushvalue(L, -1); /* copy to be left at top */ |
| 806 | lua_setfield(L, idx, fname); /* assign new table to field */ | 806 | lua_setfield(L, idx, fname); /* assign new table to field */ |
| 807 | return 0; /* false, because did not find table there */ | ||
| 807 | } | 808 | } |
| 808 | } | 809 | } |
| 809 | 810 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.112 2010/11/16 17:43:29 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.113 2010/11/16 19:20:01 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -83,7 +83,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, | |||
| 83 | 83 | ||
| 84 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); | 84 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); |
| 85 | 85 | ||
| 86 | LUALIB_API void (luaL_findtable) (lua_State *L, int idx, const char *fname); | 86 | LUALIB_API int (luaL_findtable) (lua_State *L, int idx, const char *fname); |
| 87 | 87 | ||
| 88 | LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, | 88 | LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, |
| 89 | const char *msg, int level); | 89 | const char *msg, int level); |
