@@ -983,6 +983,31 @@ void output_flex_t::add_row(table_connection_t *table_connection,
983983 }
984984}
985985
986+ static int msghandler (lua_State *L)
987+ {
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 */
999+ }
1000+
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 */
1008+ return status;
1009+ }
1010+
9861011void output_flex_t::call_process_function (int index,
9871012 osmium::OSMObject const &object)
9881013{
@@ -996,7 +1021,7 @@ void output_flex_t::call_process_function(int index,
9961021 get_options ()->extra_attributes ); // the single argument
9971022
9981023 luaX_set_context (lua_state (), this );
999- if (lua_pcall (lua_state (), 1 , 0 , 0 )) {
1024+ if (docall (lua_state (), 1 , 0 )) {
10001025 throw std::runtime_error{" Failed to execute lua processing function:"
10011026 " {}" _format (lua_tostring (lua_state (), -1 ))};
10021027 }
0 commit comments