Skip to content

Commit 4bc74b3

Browse files
committed
Refactoring: Use luaX_pushstring() helper more
Gets rid of c_str() in many places
1 parent 470092d commit 4bc74b3

File tree

7 files changed

+15
-16
lines changed

7 files changed

+15
-16
lines changed

src/flex-lua-locator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int lua_wrapper_locator::all_intersecting()
158158
int n = 0;
159159
for (auto const& name : names) {
160160
lua_pushinteger(lua_state(), ++n);
161-
lua_pushstring(lua_state(), name.c_str());
161+
luaX_pushstring(lua_state(), name);
162162
lua_rawset(lua_state(), -3);
163163
}
164164

@@ -182,7 +182,7 @@ int lua_wrapper_locator::first_intersecting()
182182
return 0;
183183
}
184184

185-
lua_pushstring(lua_state(), name.c_str());
185+
luaX_pushstring(lua_state(), name);
186186

187187
return 1;
188188
}

src/flex-lua-table.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,11 @@ int lua_wrapper_table::columns() const
503503
lua_pushinteger(lua_state(), ++n);
504504
lua_newtable(lua_state());
505505

506-
luaX_add_table_str(lua_state(), "name", column.name().c_str());
507-
luaX_add_table_str(lua_state(), "type", column.type_name().c_str());
508-
luaX_add_table_str(lua_state(), "sql_type",
509-
column.sql_type_name().c_str());
506+
luaX_add_table_str(lua_state(), "name", column.name());
507+
luaX_add_table_str(lua_state(), "type", column.type_name());
508+
luaX_add_table_str(lua_state(), "sql_type", column.sql_type_name());
510509
luaX_add_table_str(lua_state(), "sql_modifiers",
511-
column.sql_modifiers().c_str());
510+
column.sql_modifiers());
512511
luaX_add_table_bool(lua_state(), "not_null", column.not_null());
513512
luaX_add_table_bool(lua_state(), "create_only", column.create_only());
514513

src/lua-setup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void setup_lua_environment(lua_State *lua_state, std::string const &filename,
3333
if (!dir_path.empty()) {
3434
dir_path += std::filesystem::path::preferred_separator;
3535
}
36-
luaX_add_table_str(lua_state, "config_dir", dir_path.c_str());
36+
luaX_add_table_str(lua_state, "config_dir", dir_path);
3737

3838
luaX_add_table_str(lua_state, "mode", append_mode ? "append" : "create");
3939
}

src/lua-utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ void luaX_add_table_str(lua_State *lua_state, char const *key,
7676
}
7777

7878
void luaX_add_table_str(lua_State *lua_state, char const *key,
79-
char const *value, std::size_t size) noexcept
79+
std::string_view value) noexcept
8080
{
8181
lua_pushstring(lua_state, key);
82-
lua_pushlstring(lua_state, value, size);
82+
luaX_pushstring(lua_state, value);
8383
lua_rawset(lua_state, -3);
8484
}
8585

src/lua-utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void luaX_pushstring(lua_State *lua_state, std::string_view str) noexcept;
2828
void luaX_add_table_str(lua_State *lua_state, char const *key,
2929
char const *value) noexcept;
3030
void luaX_add_table_str(lua_State *lua_state, char const *key,
31-
char const *value, std::size_t size) noexcept;
31+
std::string_view value) noexcept;
3232
void luaX_add_table_int(lua_State *lua_state, char const *key,
3333
int64_t value) noexcept;
3434
void luaX_add_table_num(lua_State *lua_state, char const *key,

src/output-flex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ void output_flex_t::init_lua(std::string const &filename,
12811281
lua_createtable(lua_state(), 0, (int)properties.size());
12821282
for (auto const &property : properties) {
12831283
luaX_add_table_str(lua_state(), property.first.c_str(),
1284-
property.second.c_str());
1284+
property.second);
12851285
}
12861286
lua_rawset(lua_state(), -3);
12871287

src/tagtransform-lua.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, bool *polygon,
111111
taglist_t tags;
112112
tags.add_attributes(o);
113113
for (auto const &t : tags) {
114-
lua_pushstring(lua_state(), t.key.c_str());
115-
lua_pushstring(lua_state(), t.value.c_str());
114+
luaX_pushstring(lua_state(), t.key);
115+
luaX_pushstring(lua_state(), t.value);
116116
lua_rawset(lua_state(), -3);
117117
++sz;
118118
}
@@ -158,8 +158,8 @@ bool lua_tagtransform_t::filter_rel_member_tags(
158158
lua_newtable(lua_state()); /* relations key value table */
159159

160160
for (auto const &rel_tag : rel_tags) {
161-
lua_pushstring(lua_state(), rel_tag.key.c_str());
162-
lua_pushstring(lua_state(), rel_tag.value.c_str());
161+
luaX_pushstring(lua_state(), rel_tag.key);
162+
luaX_pushstring(lua_state(), rel_tag.value);
163163
lua_rawset(lua_state(), -3);
164164
}
165165

0 commit comments

Comments
 (0)