diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-16 14:58:02 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-16 14:58:02 -0300 |
commit | b96b0b5abbf40cbdbed7952bf35a5a27ddf75928 (patch) | |
tree | 5d9d5463cb7d3424833abab20dd87bce1f4b240f /ldblib.c | |
parent | ca13be9af784b7288d3a07d9b5bccb329086e885 (diff) | |
download | lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.tar.gz lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.tar.bz2 lua-b96b0b5abbf40cbdbed7952bf35a5a27ddf75928.zip |
Added macro 'luaL_pushfail'
The macro 'luaL_pushfail' documents all places in the standard libraries
that return nil to signal some kind of failure. It is defined as
'lua_pushnil'. The manual also got a notation (@fail) to document those
returns. The tests were changed to be agnostic regarding whether 'fail'
is 'nil' or 'false'.
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -65,7 +65,7 @@ static int db_setmetatable (lua_State *L) { | |||
65 | static int db_getuservalue (lua_State *L) { | 65 | static int db_getuservalue (lua_State *L) { |
66 | int n = (int)luaL_optinteger(L, 2, 1); | 66 | int n = (int)luaL_optinteger(L, 2, 1); |
67 | if (lua_type(L, 1) != LUA_TUSERDATA) | 67 | if (lua_type(L, 1) != LUA_TUSERDATA) |
68 | lua_pushnil(L); | 68 | luaL_pushfail(L); |
69 | else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) { | 69 | else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) { |
70 | lua_pushboolean(L, 1); | 70 | lua_pushboolean(L, 1); |
71 | return 2; | 71 | return 2; |
@@ -80,7 +80,7 @@ static int db_setuservalue (lua_State *L) { | |||
80 | luaL_checkany(L, 2); | 80 | luaL_checkany(L, 2); |
81 | lua_settop(L, 2); | 81 | lua_settop(L, 2); |
82 | if (!lua_setiuservalue(L, 1, n)) | 82 | if (!lua_setiuservalue(L, 1, n)) |
83 | lua_pushnil(L); | 83 | luaL_pushfail(L); |
84 | return 1; | 84 | return 1; |
85 | } | 85 | } |
86 | 86 | ||
@@ -159,7 +159,7 @@ static int db_getinfo (lua_State *L) { | |||
159 | } | 159 | } |
160 | else { /* stack level */ | 160 | else { /* stack level */ |
161 | if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { | 161 | if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { |
162 | lua_pushnil(L); /* level out of range */ | 162 | luaL_pushfail(L); /* level out of range */ |
163 | return 1; | 163 | return 1; |
164 | } | 164 | } |
165 | } | 165 | } |
@@ -223,7 +223,7 @@ static int db_getlocal (lua_State *L) { | |||
223 | return 2; | 223 | return 2; |
224 | } | 224 | } |
225 | else { | 225 | else { |
226 | lua_pushnil(L); /* no name (nor value) */ | 226 | luaL_pushfail(L); /* no name (nor value) */ |
227 | return 1; | 227 | return 1; |
228 | } | 228 | } |
229 | } | 229 | } |
@@ -389,8 +389,10 @@ static int db_gethook (lua_State *L) { | |||
389 | char buff[5]; | 389 | char buff[5]; |
390 | int mask = lua_gethookmask(L1); | 390 | int mask = lua_gethookmask(L1); |
391 | lua_Hook hook = lua_gethook(L1); | 391 | lua_Hook hook = lua_gethook(L1); |
392 | if (hook == NULL) /* no hook? */ | 392 | if (hook == NULL) { /* no hook? */ |
393 | lua_pushnil(L); | 393 | luaL_pushfail(L); |
394 | return 1; | ||
395 | } | ||
394 | else if (hook != hookf) /* external hook? */ | 396 | else if (hook != hookf) /* external hook? */ |
395 | lua_pushliteral(L, "external hook"); | 397 | lua_pushliteral(L, "external hook"); |
396 | else { /* hook table must exist */ | 398 | else { /* hook table must exist */ |