2
0
Эх сурвалжийг харах

'luaL_findtable' returns boolean about whether it created a new
table (to easy initializing table)

Roberto Ierusalimschy 14 жил өмнө
parent
commit
a10d495b18
2 өөрчлөгдсөн 6 нэмэгдсэн , 5 устгасан
  1. 4 3
      lauxlib.c
  2. 2 2
      lauxlib.h

+ 4 - 3
lauxlib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lauxlib.c,v 1.226 2010/11/10 17:38:10 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.227 2010/11/10 18:05:36 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -795,15 +795,16 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
 ** ensure that stack[idx][fname] has a table and push that table
 ** ensure that stack[idx][fname] has a table and push that table
 ** into the stack
 ** into the stack
 */
 */
-LUALIB_API void luaL_findtable (lua_State *L, int idx, const char *fname) {
+LUALIB_API int luaL_findtable (lua_State *L, int idx, const char *fname) {
   lua_getfield(L, idx, fname);
   lua_getfield(L, idx, fname);
-  if (lua_istable(L, -1)) return;  /* table already there */
+  if (lua_istable(L, -1)) return 1;  /* table already there */
   else {
   else {
     idx = lua_absindex(L, idx);
     idx = lua_absindex(L, idx);
     lua_pop(L, 1);  /* remove previous result */
     lua_pop(L, 1);  /* remove previous result */
     lua_newtable(L);
     lua_newtable(L);
     lua_pushvalue(L, -1);  /* copy to be left at top */
     lua_pushvalue(L, -1);  /* copy to be left at top */
     lua_setfield(L, idx, fname);  /* assign new table to field */
     lua_setfield(L, idx, fname);  /* assign new table to field */
+    return 0;  /* false, because did not find table there */
   }
   }
 }
 }
 
 

+ 2 - 2
lauxlib.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lauxlib.h,v 1.112 2010/11/16 17:43:29 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.113 2010/11/16 19:20:01 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -83,7 +83,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
 
 
 LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
 LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
 
 
-LUALIB_API void (luaL_findtable) (lua_State *L, int idx, const char *fname);
+LUALIB_API int (luaL_findtable) (lua_State *L, int idx, const char *fname);
 
 
 LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
 LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
                                   const char *msg, int level);
                                   const char *msg, int level);