1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-01 11:09:07 +00:00

Factor out lua_call_traceback.

This does a lua_pcall with the standard traceback error handler.
This commit is contained in:
david
2013-09-05 22:10:15 +00:00
parent 3ada0d56c3
commit 4fdde97639
2 changed files with 14 additions and 5 deletions

View File

@@ -165,11 +165,7 @@ lua_State *lua_setup(const char *filename)
void lua_run(lua_State *L)
{
/* The chunk as read from lua_setup is on top of the stack. Put the
traceback function before it and run it. */
lua_pushcfunction(L, traceback);
lua_insert(L, -2);
if (lua_pcall(L, 0, 0, -2) != LUA_OK && !lua_isnil(L, -1)) {
if (lua_call_traceback(L, 0, 0) != LUA_OK && !lua_isnil(L, -1)) {
report(L, "Error running the Lua script");
} else {
if (o.debug)
@@ -178,3 +174,15 @@ void lua_run(lua_State *L)
exit(EXIT_SUCCESS);
}
}
/* Returns the value of a lua_pcall of the chunk on top of the stack, with an
error handler that prints a traceback. */
int lua_call_traceback(lua_State *L, int nargs, int nresults)
{
/* The chunk to run is on top of the stack. Put the traceback function
before it and run it. */
lua_pushcfunction(L, traceback);
lua_insert(L, -2);
return lua_pcall(L, nargs, nresults, -2);
}

View File

@@ -140,5 +140,6 @@ extern "C" {
lua_State *lua_setup(const char *filename);
void lua_run(lua_State *L);
int lua_call_traceback(lua_State *L, int nargs, int nresults);
#endif