diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.124 2002/06/11 16:23:47 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.125 2002/06/13 13:44:50 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -338,6 +338,34 @@ static int string_query (lua_State *L) { | |||
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
341 | static int xpcall (lua_State *L) { | ||
342 | int status; | ||
343 | luaL_check_type(L, 1, LUA_TFUNCTION); | ||
344 | luaL_check_any(L, 2); | ||
345 | lua_pushliteral(L, LUA_TRACEBACK); | ||
346 | lua_gettable(L, LUA_REGISTRYINDEX); | ||
347 | lua_pushliteral(L, LUA_TRACEBACK); | ||
348 | lua_pushvalue(L, 1); | ||
349 | lua_settable(L, LUA_REGISTRYINDEX); | ||
350 | lua_replace(L, 1); | ||
351 | status = lua_pcall(L, lua_gettop(L) - 2, LUA_MULTRET); | ||
352 | lua_pushliteral(L, LUA_TRACEBACK); | ||
353 | lua_pushvalue(L, 1); | ||
354 | lua_settable(L, LUA_REGISTRYINDEX); | ||
355 | if (status != 0) { | ||
356 | int numres = (status == LUA_ERRRUN) ? 3 : 2; | ||
357 | lua_pushnil(L); | ||
358 | lua_insert(L, -numres); | ||
359 | return numres; | ||
360 | } | ||
361 | else { | ||
362 | lua_pushboolean(L, 1); | ||
363 | lua_insert(L, 2); | ||
364 | return lua_gettop(L) - 1; /* return `true' + all results */ | ||
365 | } | ||
366 | } | ||
367 | |||
368 | |||
341 | static int tref (lua_State *L) { | 369 | static int tref (lua_State *L) { |
342 | int level = lua_gettop(L); | 370 | int level = lua_gettop(L); |
343 | int lock = luaL_opt_int(L, 2, 1); | 371 | int lock = luaL_opt_int(L, 2, 1); |
@@ -402,7 +430,7 @@ static int doonnewstack (lua_State *L) { | |||
402 | const char *s = luaL_check_lstr(L, 1, &l); | 430 | const char *s = luaL_check_lstr(L, 1, &l); |
403 | int status = luaL_loadbuffer(L1, s, l, s); | 431 | int status = luaL_loadbuffer(L1, s, l, s); |
404 | if (status == 0) | 432 | if (status == 0) |
405 | status = lua_pcall(L1, 0, 0, 0); | 433 | status = lua_pcall(L1, 0, 0); |
406 | lua_pushnumber(L, status); | 434 | lua_pushnumber(L, status); |
407 | lua_closethread(L, L1); | 435 | lua_closethread(L, L1); |
408 | return 1; | 436 | return 1; |
@@ -639,7 +667,7 @@ static int testC (lua_State *L) { | |||
639 | else if EQ("call") { | 667 | else if EQ("call") { |
640 | int narg = getnum; | 668 | int narg = getnum; |
641 | int nres = getnum; | 669 | int nres = getnum; |
642 | lua_call(L, narg, nres); | 670 | lua_pcall(L, narg, nres); |
643 | } | 671 | } |
644 | else if EQ("loadstring") { | 672 | else if EQ("loadstring") { |
645 | size_t sl; | 673 | size_t sl; |
@@ -659,7 +687,7 @@ static int testC (lua_State *L) { | |||
659 | else if EQ("type") { | 687 | else if EQ("type") { |
660 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); | 688 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); |
661 | } | 689 | } |
662 | else luaL_verror(L, "unknown instruction %s", buff); | 690 | else luaL_error(L, "unknown instruction %s", buff); |
663 | } | 691 | } |
664 | return 0; | 692 | return 0; |
665 | } | 693 | } |
@@ -677,6 +705,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
677 | {"loadlib", loadlib}, | 705 | {"loadlib", loadlib}, |
678 | {"stacklevel", stacklevel}, | 706 | {"stacklevel", stacklevel}, |
679 | {"querystr", string_query}, | 707 | {"querystr", string_query}, |
708 | {"xpcall", xpcall}, | ||
680 | {"querytab", table_query}, | 709 | {"querytab", table_query}, |
681 | {"testC", testC}, | 710 | {"testC", testC}, |
682 | {"ref", tref}, | 711 | {"ref", tref}, |