Skip to content

Commit 95b9f81

Browse files
committed
New helper function luaX_pushstring()
1 parent 0de33f5 commit 95b9f81

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/lua-utils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ void *luaX_get_context(lua_State *lua_state) noexcept
5858

5959
#endif
6060

61+
void luaX_pushstring(lua_State *lua_state, std::string_view str) noexcept
62+
{
63+
lua_pushlstring(lua_state, str.data(), str.size());
64+
}
65+
6166
void luaX_add_table_str(lua_State *lua_state, char const *key,
6267
char const *value) noexcept
6368
{

src/lua-utils.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
#include <cassert>
1919
#include <cstdint>
20+
#include <string_view>
2021
#include <utility>
2122

2223
void luaX_set_context(lua_State *lua_state, void *ptr) noexcept;
2324
void *luaX_get_context(lua_State *lua_state) noexcept;
2425

26+
void luaX_pushstring(lua_State *lua_state, std::string_view str) noexcept;
27+
2528
void luaX_add_table_str(lua_State *lua_state, char const *key,
2629
char const *value) noexcept;
2730
void luaX_add_table_str(lua_State *lua_state, char const *key,

src/output-flex.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ int output_flex_t::table_tostring()
530530
auto const &table = get_table_from_param();
531531

532532
std::string const str{fmt::format("osm2pgsql.Table[{}]", table.name())};
533-
lua_pushstring(lua_state(), str.c_str());
533+
luaX_pushstring(lua_state(), str);
534534

535535
return 1;
536536
}
@@ -689,8 +689,8 @@ int output_flex_t::table_insert()
689689
} catch (not_null_exception const &e) {
690690
copy_mgr->rollback_line();
691691
lua_pushboolean(lua_state(), false);
692-
lua_pushstring(lua_state(), "null value in not null column.");
693-
lua_pushstring(lua_state(), e.column().name().c_str());
692+
lua_pushliteral(lua_state(), "null value in not null column.");
693+
luaX_pushstring(lua_state(), e.column().name());
694694
push_osm_object_to_lua_stack(lua_state(), object);
695695
table_connection.increment_not_null_error_counter();
696696
return 4;
@@ -730,14 +730,14 @@ int output_flex_t::table_columns()
730730
int output_flex_t::table_name()
731731
{
732732
auto const &table = get_table_from_param();
733-
lua_pushstring(lua_state(), table.name().c_str());
733+
luaX_pushstring(lua_state(), table.name());
734734
return 1;
735735
}
736736

737737
int output_flex_t::table_schema()
738738
{
739739
auto const &table = get_table_from_param();
740-
lua_pushstring(lua_state(), table.schema().c_str());
740+
luaX_pushstring(lua_state(), table.schema());
741741
return 1;
742742
}
743743

@@ -758,7 +758,7 @@ int output_flex_t::expire_output_tostring()
758758
expire_output.minzoom(), expire_output.maxzoom(),
759759
expire_output.filename(), expire_output.schema(),
760760
expire_output.table());
761-
lua_pushstring(lua_state(), str.c_str());
761+
luaX_pushstring(lua_state(), str);
762762

763763
return 1;
764764
}
@@ -783,23 +783,23 @@ int output_flex_t::expire_output_filename()
783783
{
784784
auto const &expire_output = get_expire_output_from_param();
785785

786-
lua_pushstring(lua_state(), expire_output.filename().c_str());
786+
luaX_pushstring(lua_state(), expire_output.filename());
787787
return 1;
788788
}
789789

790790
int output_flex_t::expire_output_schema()
791791
{
792792
auto const &expire_output = get_expire_output_from_param();
793793

794-
lua_pushstring(lua_state(), expire_output.schema().c_str());
794+
luaX_pushstring(lua_state(), expire_output.schema());
795795
return 1;
796796
}
797797

798798
int output_flex_t::expire_output_table()
799799
{
800800
auto const &expire_output = get_expire_output_from_param();
801801

802-
lua_pushstring(lua_state(), expire_output.table().c_str());
802+
luaX_pushstring(lua_state(), expire_output.table());
803803
return 1;
804804
}
805805

@@ -1338,7 +1338,7 @@ void output_flex_t::init_lua(std::string const &filename,
13381338

13391339
luaX_add_table_int(lua_state(), "stage", 1);
13401340

1341-
lua_pushstring(lua_state(), "properties");
1341+
lua_pushliteral(lua_state(), "properties");
13421342
lua_createtable(lua_state(), 0, (int)properties.size());
13431343
for (auto const &property : properties) {
13441344
luaX_add_table_str(lua_state(), property.first.c_str(),

0 commit comments

Comments
 (0)