diff options
Diffstat (limited to 'src/lua/ldblib.c')
| -rw-r--r-- | src/lua/ldblib.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/lua/ldblib.c b/src/lua/ldblib.c index 59eb8f0..5a326ad 100644 --- a/src/lua/ldblib.c +++ b/src/lua/ldblib.c | |||
| @@ -281,25 +281,33 @@ static int db_setupvalue (lua_State *L) { | |||
| 281 | ** Check whether a given upvalue from a given closure exists and | 281 | ** Check whether a given upvalue from a given closure exists and |
| 282 | ** returns its index | 282 | ** returns its index |
| 283 | */ | 283 | */ |
| 284 | static int checkupval (lua_State *L, int argf, int argnup) { | 284 | static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) { |
| 285 | void *id; | ||
| 285 | int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */ | 286 | int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */ |
| 286 | luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ | 287 | luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ |
| 287 | luaL_argcheck(L, (lua_getupvalue(L, argf, nup) != NULL), argnup, | 288 | id = lua_upvalueid(L, argf, nup); |
| 288 | "invalid upvalue index"); | 289 | if (pnup) { |
| 289 | return nup; | 290 | luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index"); |
| 291 | *pnup = nup; | ||
| 292 | } | ||
| 293 | return id; | ||
| 290 | } | 294 | } |
| 291 | 295 | ||
| 292 | 296 | ||
| 293 | static int db_upvalueid (lua_State *L) { | 297 | static int db_upvalueid (lua_State *L) { |
| 294 | int n = checkupval(L, 1, 2); | 298 | void *id = checkupval(L, 1, 2, NULL); |
| 295 | lua_pushlightuserdata(L, lua_upvalueid(L, 1, n)); | 299 | if (id != NULL) |
| 300 | lua_pushlightuserdata(L, id); | ||
| 301 | else | ||
| 302 | luaL_pushfail(L); | ||
| 296 | return 1; | 303 | return 1; |
| 297 | } | 304 | } |
| 298 | 305 | ||
| 299 | 306 | ||
| 300 | static int db_upvaluejoin (lua_State *L) { | 307 | static int db_upvaluejoin (lua_State *L) { |
| 301 | int n1 = checkupval(L, 1, 2); | 308 | int n1, n2; |
| 302 | int n2 = checkupval(L, 3, 4); | 309 | checkupval(L, 1, 2, &n1); |
| 310 | checkupval(L, 3, 4, &n2); | ||
| 303 | luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); | 311 | luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); |
| 304 | luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); | 312 | luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); |
| 305 | lua_upvaluejoin(L, 1, n1, 3, n2); | 313 | lua_upvaluejoin(L, 1, n1, 3, n2); |
| @@ -440,10 +448,7 @@ static int db_traceback (lua_State *L) { | |||
| 440 | static int db_setcstacklimit (lua_State *L) { | 448 | static int db_setcstacklimit (lua_State *L) { |
| 441 | int limit = (int)luaL_checkinteger(L, 1); | 449 | int limit = (int)luaL_checkinteger(L, 1); |
| 442 | int res = lua_setcstacklimit(L, limit); | 450 | int res = lua_setcstacklimit(L, limit); |
| 443 | if (res == 0) | 451 | lua_pushinteger(L, res); |
| 444 | lua_pushboolean(L, 0); | ||
| 445 | else | ||
| 446 | lua_pushinteger(L, res); | ||
| 447 | return 1; | 452 | return 1; |
| 448 | } | 453 | } |
| 449 | 454 | ||
