4747#include < mutex>
4848#include < stdexcept>
4949#include < string>
50+ #include < string_view>
5051
5152// Mutex used to coordinate access to Lua code
5253static std::mutex lua_mutex;
@@ -97,9 +98,6 @@ TRAMPOLINE(expire_output_schema, schema)
9798TRAMPOLINE(expire_output_table, table)
9899TRAMPOLINE(expire_output_tostring, __tostring)
99100
100- static char const *const osm2pgsql_object_metatable =
101- "osm2pgsql.object_metatable";
102-
103101prepared_lua_function_t::prepared_lua_function_t(lua_State *lua_state,
104102 calling_context context,
105103 char const *name, int nresults)
@@ -125,6 +123,8 @@ prepared_lua_function_t::prepared_lua_function_t(lua_State *lua_state,
125123
126124namespace {
127125
126+ std::string_view const osm2pgsql_object_metatable = " osm2pgsql.OSMObject" ;
127+
128128void push_osm_object_to_lua_stack (lua_State *lua_state,
129129 osmium::OSMObject const &object)
130130{
@@ -191,7 +191,7 @@ void push_osm_object_to_lua_stack(lua_State *lua_state,
191191 lua_rawset (lua_state, -3 );
192192
193193 // Set the metatable of this object
194- lua_pushlightuserdata (lua_state, ( void *) osm2pgsql_object_metatable);
194+ luaX_pushstring (lua_state, osm2pgsql_object_metatable);
195195 lua_gettable (lua_state, LUA_REGISTRYINDEX);
196196 lua_setmetatable (lua_state, -2 );
197197}
@@ -1370,6 +1370,8 @@ void output_flex_t::init_lua(std::string const &filename,
13701370
13711371 // Store the methods on OSM objects in its metatable.
13721372 lua_getglobal (lua_state (), " object_metatable" );
1373+ luaX_pushstring (lua_state (), osm2pgsql_object_metatable);
1374+ lua_setfield (lua_state (), -2 , " __name" );
13731375 lua_getfield (lua_state (), -1 , " __index" );
13741376 luaX_add_table_func (lua_state (), " get_bbox" , lua_trampoline_app_get_bbox);
13751377 luaX_add_table_func (lua_state (), " as_linestring" ,
@@ -1391,7 +1393,7 @@ void output_flex_t::init_lua(std::string const &filename,
13911393 // Store the global object "object_metatable" defined in the init.lua
13921394 // script in the registry and then remove the global object. It will
13931395 // later be used as metatable for OSM objects.
1394- lua_pushlightuserdata (lua_state (), ( void *) osm2pgsql_object_metatable);
1396+ luaX_pushstring (lua_state (), osm2pgsql_object_metatable);
13951397 lua_getglobal (lua_state (), " object_metatable" );
13961398 lua_settable (lua_state (), LUA_REGISTRYINDEX);
13971399 lua_pushnil (lua_state ());
0 commit comments