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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user