@@ -804,6 +804,15 @@ int output_flex_t::expire_output_table()
804804 return 1 ;
805805}
806806
807+ void output_flex_t::call_lua_function (prepared_lua_function_t func)
808+ {
809+ lua_pushvalue (lua_state (), func.index ());
810+ if (luaX_pcall (lua_state (), 0 , func.nresults ())) {
811+ throw fmt_error (" Failed to execute Lua function 'osm2pgsql.{}': {}." ,
812+ func.name (), lua_tostring (lua_state (), -1 ));
813+ }
814+ }
815+
807816void output_flex_t::call_lua_function (prepared_lua_function_t func,
808817 osmium::OSMObject const &object)
809818{
@@ -823,6 +832,13 @@ void output_flex_t::call_lua_function(prepared_lua_function_t func,
823832 m_calling_context = calling_context::main;
824833}
825834
835+ void output_flex_t::get_mutex_and_call_lua_function (
836+ prepared_lua_function_t func)
837+ {
838+ std::lock_guard<std::mutex> const guard{lua_mutex};
839+ call_lua_function (func);
840+ }
841+
826842void output_flex_t::get_mutex_and_call_lua_function (
827843 prepared_lua_function_t func, osmium::OSMObject const &object)
828844{
@@ -960,11 +976,32 @@ void output_flex_t::sync()
960976 }
961977}
962978
963- void output_flex_t::after_nodes () { flush_tables (m_table_connections); }
979+ void output_flex_t::after_nodes ()
980+ {
981+ if (m_after_nodes) {
982+ get_mutex_and_call_lua_function (m_after_nodes);
983+ }
984+
985+ flush_tables (m_table_connections);
986+ }
964987
965- void output_flex_t::after_ways () { flush_tables (m_table_connections); }
988+ void output_flex_t::after_ways ()
989+ {
990+ if (m_after_ways) {
991+ get_mutex_and_call_lua_function (m_after_ways);
992+ }
966993
967- void output_flex_t::after_relations () { flush_tables (m_table_connections); }
994+ flush_tables (m_table_connections);
995+ }
996+
997+ void output_flex_t::after_relations ()
998+ {
999+ if (m_after_relations) {
1000+ get_mutex_and_call_lua_function (m_after_relations);
1001+ }
1002+
1003+ flush_tables (m_table_connections);
1004+ }
9681005
9691006void output_flex_t::stop ()
9701007{
@@ -1138,7 +1175,9 @@ output_flex_t::output_flex_t(output_flex_t const *other,
11381175 m_copy_thread(std::move(copy_thread)), m_lua_state(other->m_lua_state),
11391176 m_process_node(other->m_process_node), m_process_way(other->m_process_way),
11401177 m_process_relation(other->m_process_relation),
1141- m_select_relation_members(other->m_select_relation_members)
1178+ m_select_relation_members(other->m_select_relation_members),
1179+ m_after_nodes(other->m_after_nodes), m_after_ways(other->m_after_ways),
1180+ m_after_relations(other->m_after_relations)
11421181{
11431182 for (auto &table : *m_tables) {
11441183 table.prepare (m_db_connection);
@@ -1369,6 +1408,12 @@ void output_flex_t::init_lua(std::string const &filename,
13691408 m_select_relation_members = prepared_lua_function_t {
13701409 lua_state (), calling_context::select_relation_members,
13711410 " select_relation_members" , 1 };
1411+ m_after_nodes = prepared_lua_function_t {lua_state (), calling_context::main,
1412+ " after_nodes" };
1413+ m_after_ways = prepared_lua_function_t {lua_state (), calling_context::main,
1414+ " after_ways" };
1415+ m_after_relations = prepared_lua_function_t {
1416+ lua_state (), calling_context::main, " after_relations" };
13721417
13731418 lua_remove (lua_state (), 1 ); // global "osm2pgsql"
13741419}
0 commit comments