Lua API: Fix some places that weren't handling strings correctly.

Lua strings can contain nulls. The affected places would truncate such strings.
This commit is contained in:
Celtic Minstrel 2024-09-17 13:57:54 -04:00
parent 7e912d532f
commit 802869bf23
2 changed files with 5 additions and 5 deletions

View file

@ -569,7 +569,7 @@ namespace {
void operator()(double d) const
{ lua_pushnumber(L, d); }
void operator()(const std::string& s) const
{ lua_pushstring(L, s.c_str()); }
{ lua_pushlstring(L, s.c_str(), s.size()); }
void operator()(const t_string& s) const
{ luaW_pushtstring(L, s); }
};
@ -590,7 +590,7 @@ bool luaW_toscalar(lua_State *L, int index, config::attribute_value& v)
v = lua_tonumber(L, -1);
break;
case LUA_TSTRING:
v = lua_tostring(L, -1);
v = std::string(luaW_tostring(L, -1));
break;
case LUA_TUSERDATA:
{
@ -1041,7 +1041,7 @@ bool luaW_checkvariable(lua_State *L, variable_access_create& v, int n)
v.as_scalar() = lua_tonumber(L, n);
return true;
case LUA_TSTRING:
v.as_scalar() = lua_tostring(L, n);
v.as_scalar() = std::string(luaW_tostring(L, n));
return true;
case LUA_TUSERDATA:
if (t_string * t_str = static_cast<t_string*> (luaL_testudata(L, n, tstringKey))) {

View file

@ -93,13 +93,13 @@ namespace lua_check_impl
std::enable_if_t<std::is_same_v<T, std::string>, std::string>
lua_check(lua_State *L, int n)
{
return luaL_checkstring(L, n);
return std::string(luaW_tostring(L, n));
}
template<typename T>
std::enable_if_t<std::is_same_v<T, std::string>, std::string>
lua_to_or_default(lua_State *L, int n, const T& def)
{
return luaL_optstring(L, n, def.c_str());
return std::string(luaW_tostring_or_default(L, n, def));
}
template<typename T>
std::enable_if_t<std::is_same_v<T, std::string>, void>