diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-12 17:57:40 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-12 17:57:40 -0300 |
commit | a3addae03634794b841b6c8c4dd8ff83542d8896 (patch) | |
tree | 66695864f7bd56c295ad7cd6a6465845103cd424 /lauxlib.c | |
parent | ad40bb1181d08821af6789147a28aa8370533d11 (diff) | |
download | lua-a3addae03634794b841b6c8c4dd8ff83542d8896.tar.gz lua-a3addae03634794b841b6c8c4dd8ff83542d8896.tar.bz2 lua-a3addae03634794b841b6c8c4dd8ff83542d8896.zip |
lua_gettable and similars return type of gotten value
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 18 |
1 files changed, 7 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.258 2014/02/11 17:39:15 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.259 2014/02/19 13:48:53 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 | */ |
@@ -172,8 +172,7 @@ static int typeerror (lua_State *L, int arg, const char *tname) { | |||
172 | const char *msg; | 172 | const char *msg; |
173 | const char *typearg = luaL_typename(L, arg); | 173 | const char *typearg = luaL_typename(L, arg); |
174 | if (lua_getmetatable(L, arg)) { | 174 | if (lua_getmetatable(L, arg)) { |
175 | lua_getfield(L, -1, "__name"); | 175 | if (lua_getfield(L, -1, "__name") == LUA_TSTRING) |
176 | if (lua_isstring(L, -1)) | ||
177 | typearg = lua_tostring(L, -1); | 176 | typearg = lua_tostring(L, -1); |
178 | } | 177 | } |
179 | else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA) | 178 | else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA) |
@@ -719,8 +718,7 @@ LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { | |||
719 | if (!lua_getmetatable(L, obj)) /* no metatable? */ | 718 | if (!lua_getmetatable(L, obj)) /* no metatable? */ |
720 | return 0; | 719 | return 0; |
721 | lua_pushstring(L, event); | 720 | lua_pushstring(L, event); |
722 | lua_rawget(L, -2); | 721 | if (lua_rawget(L, -2) == LUA_TNIL) { /* is metafield nil? */ |
723 | if (lua_isnil(L, -1)) { | ||
724 | lua_pop(L, 2); /* remove metatable and metafield */ | 722 | lua_pop(L, 2); /* remove metatable and metafield */ |
725 | return 0; | 723 | return 0; |
726 | } | 724 | } |
@@ -802,8 +800,7 @@ static const char *luaL_findtable (lua_State *L, int idx, | |||
802 | e = strchr(fname, '.'); | 800 | e = strchr(fname, '.'); |
803 | if (e == NULL) e = fname + strlen(fname); | 801 | if (e == NULL) e = fname + strlen(fname); |
804 | lua_pushlstring(L, fname, e - fname); | 802 | lua_pushlstring(L, fname, e - fname); |
805 | lua_rawget(L, -2); | 803 | if (lua_rawget(L, -2) == LUA_TNIL) { /* no such field? */ |
806 | if (lua_isnil(L, -1)) { /* no such field? */ | ||
807 | lua_pop(L, 1); /* remove this nil */ | 804 | lua_pop(L, 1); /* remove this nil */ |
808 | lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ | 805 | lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ |
809 | lua_pushlstring(L, fname, e - fname); | 806 | lua_pushlstring(L, fname, e - fname); |
@@ -840,8 +837,7 @@ static int libsize (const luaL_Reg *l) { | |||
840 | LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname, | 837 | LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname, |
841 | int sizehint) { | 838 | int sizehint) { |
842 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */ | 839 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */ |
843 | lua_getfield(L, -1, modname); /* get _LOADED[modname] */ | 840 | if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no _LOADED[modname]? */ |
844 | if (!lua_istable(L, -1)) { /* not found? */ | ||
845 | lua_pop(L, 1); /* remove previous result */ | 841 | lua_pop(L, 1); /* remove previous result */ |
846 | /* try global variable (and create one if it does not exist) */ | 842 | /* try global variable (and create one if it does not exist) */ |
847 | lua_pushglobaltable(L); | 843 | lua_pushglobaltable(L); |
@@ -893,8 +889,8 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { | |||
893 | ** into the stack | 889 | ** into the stack |
894 | */ | 890 | */ |
895 | LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { | 891 | LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { |
896 | lua_getfield(L, idx, fname); | 892 | if (lua_getfield(L, idx, fname) == LUA_TTABLE) |
897 | if (lua_istable(L, -1)) return 1; /* table already there */ | 893 | return 1; /* table already there */ |
898 | else { | 894 | else { |
899 | lua_pop(L, 1); /* remove previous result */ | 895 | lua_pop(L, 1); /* remove previous result */ |
900 | idx = lua_absindex(L, idx); | 896 | idx = lua_absindex(L, idx); |