Skip to content

Commit 771baaa

Browse files
authored
Merge pull request #2340 from joto/refactor-class-names
Consistent naming and type for "Lua class names"
2 parents a43066d + e39172c commit 771baaa

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

src/flex-lua-expire-output.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int setup_flex_expire_output(lua_State *lua_state,
8888
void *ptr = lua_newuserdata(lua_state, sizeof(std::size_t));
8989
auto *num = new (ptr) std::size_t{};
9090
*num = expire_outputs->size() - 1;
91-
luaL_getmetatable(lua_state, osm2pgsql_expire_output_name);
91+
luaL_getmetatable(lua_state, OSM2PGSQL_EXPIRE_OUTPUT_CLASS);
9292
lua_setmetatable(lua_state, -2);
9393

9494
return 1;
@@ -100,7 +100,7 @@ int setup_flex_expire_output(lua_State *lua_state,
100100
void lua_wrapper_expire_output::init(lua_State *lua_state)
101101
{
102102
lua_getglobal(lua_state, "osm2pgsql");
103-
if (luaL_newmetatable(lua_state, osm2pgsql_expire_output_name) != 1) {
103+
if (luaL_newmetatable(lua_state, OSM2PGSQL_EXPIRE_OUTPUT_CLASS) != 1) {
104104
throw std::runtime_error{"Internal error: Lua newmetatable failed."};
105105
}
106106
lua_pushvalue(lua_state, -1); // Copy of new metatable

src/flex-lua-expire-output.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class expire_output_t;
1919
struct lua_State;
2020

21-
static char const *const osm2pgsql_expire_output_name =
21+
static char const *const OSM2PGSQL_EXPIRE_OUTPUT_CLASS =
2222
"osm2pgsql.ExpireOutput";
2323

2424
int setup_flex_expire_output(lua_State *lua_state,

src/flex-lua-geom.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515

1616
#include <lua.hpp>
1717

18-
static char const *const osm2pgsql_geometry_class = "osm2pgsql.Geometry";
18+
static char const *const OSM2PGSQL_GEOMETRY_CLASS = "osm2pgsql.Geometry";
1919

2020
geom::geometry_t *create_lua_geometry_object(lua_State *lua_state)
2121
{
2222
void *ptr = lua_newuserdata(lua_state, sizeof(geom::geometry_t));
2323
new (ptr) geom::geometry_t{};
2424

2525
// Set the metatable of this object
26-
luaL_getmetatable(lua_state, osm2pgsql_geometry_class);
26+
luaL_getmetatable(lua_state, OSM2PGSQL_GEOMETRY_CLASS);
2727
lua_setmetatable(lua_state, -2);
2828

2929
return static_cast<geom::geometry_t *>(ptr);
3030
}
3131

3232
geom::geometry_t *unpack_geometry(lua_State *lua_state, int n) noexcept
3333
{
34-
void *user_data = luaL_checkudata(lua_state, n, osm2pgsql_geometry_class);
34+
void *user_data = luaL_checkudata(lua_state, n, OSM2PGSQL_GEOMETRY_CLASS);
3535
luaL_argcheck(lua_state, user_data != nullptr, n, "'Geometry' expected");
3636
return static_cast<geom::geometry_t *>(user_data);
3737
}
@@ -300,7 +300,7 @@ int geom_transform(lua_State *lua_state)
300300
void init_geometry_class(lua_State *lua_state)
301301
{
302302
lua_getglobal(lua_state, "osm2pgsql");
303-
if (luaL_newmetatable(lua_state, osm2pgsql_geometry_class) != 1) {
303+
if (luaL_newmetatable(lua_state, OSM2PGSQL_GEOMETRY_CLASS) != 1) {
304304
throw std::runtime_error{"Internal error: Lua newmetatable failed."};
305305
}
306306
lua_pushvalue(lua_state, -1); // Copy of new metatable

src/flex-lua-locator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int setup_flex_locator(lua_State *lua_state, std::vector<locator_t> *locators)
5959
void *ptr = lua_newuserdata(lua_state, sizeof(std::size_t));
6060
auto *num = new (ptr) std::size_t{};
6161
*num = locators->size() - 1;
62-
luaL_getmetatable(lua_state, osm2pgsql_locator_name);
62+
luaL_getmetatable(lua_state, OSM2PGSQL_LOCATOR_CLASS);
6363
lua_setmetatable(lua_state, -2);
6464

6565
return 1;
@@ -71,7 +71,7 @@ void lua_wrapper_locator::init(lua_State *lua_state,
7171
s_connection_params = connection_params;
7272

7373
lua_getglobal(lua_state, "osm2pgsql");
74-
if (luaL_newmetatable(lua_state, osm2pgsql_locator_name) != 1) {
74+
if (luaL_newmetatable(lua_state, OSM2PGSQL_LOCATOR_CLASS) != 1) {
7575
throw std::runtime_error{"Internal error: Lua newmetatable failed."};
7676
}
7777
lua_pushvalue(lua_state, -1); // Copy of new metatable

src/flex-lua-locator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class pg_conn_t;
2323

2424
struct lua_State;
2525

26-
static char const *const osm2pgsql_locator_name = "osm2pgsql.Locator";
26+
static char const *const OSM2PGSQL_LOCATOR_CLASS = "osm2pgsql.Locator";
2727

2828
int setup_flex_locator(lua_State *lua_state, std::vector<locator_t> *locators);
2929

src/flex-lua-table.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ std::size_t idx_from_userdata(lua_State *lua_state, int idx,
195195
throw std::runtime_error{"Expire output must be of type ExpireOutput."};
196196
}
197197

198-
luaL_getmetatable(lua_state, osm2pgsql_expire_output_name);
198+
luaL_getmetatable(lua_state, OSM2PGSQL_EXPIRE_OUTPUT_CLASS);
199199
if (!lua_rawequal(lua_state, -1, -2)) {
200200
throw std::runtime_error{"Expire output must be of type ExpireOutput."};
201201
}
@@ -445,7 +445,7 @@ int setup_flex_table(lua_State *lua_state, std::vector<flex_table_t> *tables,
445445
void *ptr = lua_newuserdata(lua_state, sizeof(std::size_t));
446446
auto *num = new (ptr) std::size_t{};
447447
*num = tables->size() - 1;
448-
luaL_getmetatable(lua_state, osm2pgsql_table_name);
448+
luaL_getmetatable(lua_state, OSM2PGSQL_TABLE_CLASS);
449449
lua_setmetatable(lua_state, -2);
450450

451451
return 1;
@@ -457,7 +457,7 @@ int setup_flex_table(lua_State *lua_state, std::vector<flex_table_t> *tables,
457457
void lua_wrapper_table::init(lua_State *lua_state)
458458
{
459459
lua_getglobal(lua_state, "osm2pgsql");
460-
if (luaL_newmetatable(lua_state, osm2pgsql_table_name) != 1) {
460+
if (luaL_newmetatable(lua_state, OSM2PGSQL_TABLE_CLASS) != 1) {
461461
throw std::runtime_error{"Internal error: Lua newmetatable failed."};
462462
}
463463
lua_pushvalue(lua_state, -1); // Copy of new metatable

src/flex-lua-table.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class expire_output_t;
1919
class flex_table_t;
2020
struct lua_State;
2121

22-
static char const *const osm2pgsql_table_name = "osm2pgsql.Table";
22+
static char const *const OSM2PGSQL_TABLE_CLASS = "osm2pgsql.Table";
2323

2424
int setup_flex_table(lua_State *lua_state, std::vector<flex_table_t> *tables,
2525
std::vector<expire_output_t> *expire_outputs,

src/gen/osm2pgsql-gen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ genproc_t::genproc_t(std::string const &filename,
565565
luaX_add_table_func(lua_state(), "run_sql", lua_trampoline_app_run_sql);
566566

567567
lua_getglobal(lua_state(), "osm2pgsql");
568-
if (luaL_newmetatable(lua_state(), osm2pgsql_expire_output_name) != 1) {
568+
if (luaL_newmetatable(lua_state(), OSM2PGSQL_EXPIRE_OUTPUT_CLASS) != 1) {
569569
throw std::runtime_error{"Internal error: Lua newmetatable failed."};
570570
}
571571
lua_pushvalue(lua_state(), -1); // Copy of new metatable

src/output-flex.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ prepared_lua_function_t::prepared_lua_function_t(lua_State *lua_state,
120120

121121
namespace {
122122

123-
std::string_view const osm2pgsql_object_metatable = "osm2pgsql.OSMObject";
123+
char const *const OSM2PGSQL_OSMOBJECT_CLASS = "osm2pgsql.OSMObject";
124124

125125
void push_osm_object_to_lua_stack(lua_State *lua_state,
126126
osmium::OSMObject const &object)
@@ -188,7 +188,7 @@ void push_osm_object_to_lua_stack(lua_State *lua_state,
188188
lua_rawset(lua_state, -3);
189189

190190
// Set the metatable of this object
191-
luaX_pushstring(lua_state, osm2pgsql_object_metatable);
191+
lua_pushstring(lua_state, OSM2PGSQL_OSMOBJECT_CLASS);
192192
lua_gettable(lua_state, LUA_REGISTRYINDEX);
193193
lua_setmetatable(lua_state, -2);
194194
}
@@ -312,7 +312,7 @@ void check_for_object(lua_State *lua_state, char const *const function_name)
312312
}
313313

314314
if (lua_getmetatable(lua_state, 1)) {
315-
luaL_getmetatable(lua_state, osm2pgsql_object_metatable.data());
315+
luaL_getmetatable(lua_state, OSM2PGSQL_OSMOBJECT_CLASS);
316316
if (lua_rawequal(lua_state, -1, -2)) {
317317
lua_pop(lua_state, 2); // remove the two metatables
318318
return;
@@ -608,19 +608,19 @@ int output_flex_t::app_define_expire_output()
608608
flex_table_t &output_flex_t::get_table_from_param()
609609
{
610610
return get_from_idx_param(lua_state(), m_tables.get(),
611-
osm2pgsql_table_name);
611+
OSM2PGSQL_TABLE_CLASS);
612612
}
613613

614614
expire_output_t &output_flex_t::get_expire_output_from_param()
615615
{
616616
return get_from_idx_param(lua_state(), m_expire_outputs.get(),
617-
osm2pgsql_expire_output_name);
617+
OSM2PGSQL_EXPIRE_OUTPUT_CLASS);
618618
}
619619

620620
locator_t &output_flex_t::get_locator_from_param()
621621
{
622622
return get_from_idx_param(lua_state(), m_locators.get(),
623-
osm2pgsql_locator_name);
623+
OSM2PGSQL_LOCATOR_CLASS);
624624
}
625625

626626
bool output_flex_t::way_cache_t::init(middle_query_t const &middle, osmid_t id)
@@ -745,7 +745,7 @@ int output_flex_t::table_insert()
745745

746746
// The first parameter is the table object.
747747
auto &table_connection = m_table_connections.at(
748-
idx_from_param(lua_state(), osm2pgsql_table_name));
748+
idx_from_param(lua_state(), OSM2PGSQL_TABLE_CLASS));
749749

750750
// The second parameter must be a Lua table with the contents for the
751751
// fields.
@@ -1273,7 +1273,7 @@ void output_flex_t::init_lua(std::string const &filename,
12731273

12741274
// Store the methods on OSM objects in its metatable.
12751275
lua_getglobal(lua_state(), "object_metatable");
1276-
luaX_pushstring(lua_state(), osm2pgsql_object_metatable);
1276+
lua_pushstring(lua_state(), OSM2PGSQL_OSMOBJECT_CLASS);
12771277
lua_setfield(lua_state(), -2, "__name");
12781278
lua_getfield(lua_state(), -1, "__index");
12791279
luaX_add_table_func(lua_state(), "get_bbox", lua_trampoline_app_get_bbox);
@@ -1296,7 +1296,7 @@ void output_flex_t::init_lua(std::string const &filename,
12961296
// Store the global object "object_metatable" defined in the init.lua
12971297
// script in the registry and then remove the global object. It will
12981298
// later be used as metatable for OSM objects.
1299-
luaX_pushstring(lua_state(), osm2pgsql_object_metatable);
1299+
lua_pushstring(lua_state(), OSM2PGSQL_OSMOBJECT_CLASS);
13001300
lua_getglobal(lua_state(), "object_metatable");
13011301
lua_settable(lua_state(), LUA_REGISTRYINDEX);
13021302
lua_pushnil(lua_state());

0 commit comments

Comments
 (0)