@@ -983,28 +983,32 @@ void output_flex_t::add_row(table_connection_t *table_connection,
983983 }
984984}
985985
986- static int msghandler (lua_State *L )
986+ static int msghandler (lua_State *lua_state )
987987{
988- const char *msg = lua_tostring (L, 1 );
989- if (msg == NULL ) { /* is error object not a string? */
990- if (luaL_callmeta (L, 1 , " __tostring" ) && /* does it have a metamethod */
991- lua_type (L, -1 ) == LUA_TSTRING) /* that produces a string? */
992- return 1 ; /* that is the message */
993- else
994- msg = lua_pushfstring (L, " (error object is a %s value)" ,
995- luaL_typename (L, 1 ));
996- }
997- luaL_traceback (L, L, msg, 1 ); /* append a standard traceback */
998- return 1 ; /* return the traceback */
988+ assert (lua_state);
989+
990+ char const *msg = lua_tostring (lua_state, 1 );
991+ if (msg == nullptr ) { // is error object not a string?
992+ if (luaL_callmeta (lua_state, 1 , " __tostring" ) && // does it have a metamethod
993+ lua_type (lua_state, -1 ) == LUA_TSTRING) { // that produces a string?
994+ return 1 ; // that is the message
995+ }
996+ else {
997+ msg = lua_pushfstring (lua_state, " (error object is a %s value)" ,
998+ luaL_typename (lua_state, 1 ));
999+ }
1000+ }
1001+ luaL_traceback (lua_state, lua_state, msg, 1 ); // append a standard traceback
1002+ return 1 ; // return the traceback
9991003}
10001004
1001- static int docall (lua_State *L, int narg, int nres) {
1002- int status;
1003- int base = lua_gettop (L) - narg; /* function index */
1004- lua_pushcfunction (L , msghandler); /* push message handler */
1005- lua_insert (L , base); /* put it under function and args */
1006- status = lua_pcall (L , narg, nres, base);
1007- lua_remove (L , base); /* remove message handler from the stack */
1005+ int output_flex_t::do_pcall ( int narg, int nres)
1006+ {
1007+ int const base = lua_gettop (lua_state ()) - narg; // function index
1008+ lua_pushcfunction (lua_state () , msghandler); // push message handler
1009+ lua_insert (lua_state () , base); // put it under function and args
1010+ int status = lua_pcall (lua_state () , narg, nres, base);
1011+ lua_remove (lua_state () , base); // remove message handler from the stack
10081012 return status;
10091013}
10101014
@@ -1021,7 +1025,7 @@ void output_flex_t::call_process_function(int index,
10211025 get_options ()->extra_attributes ); // the single argument
10221026
10231027 luaX_set_context (lua_state (), this );
1024- if (docall ( lua_state (), 1 , 0 )) {
1028+ if (do_pcall ( 1 , 0 )) {
10251029 throw std::runtime_error{" Failed to execute lua processing function:"
10261030 " {}" _format (lua_tostring (lua_state (), -1 ))};
10271031 }
0 commit comments