diff --git a/src/scripting/lua_common.cpp b/src/scripting/lua_common.cpp index 26cc34861c9..e83d86c50a9 100644 --- a/src/scripting/lua_common.cpp +++ b/src/scripting/lua_common.cpp @@ -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 (luaL_testudata(L, n, tstringKey))) { diff --git a/src/scripting/push_check.hpp b/src/scripting/push_check.hpp index 75a230c3267..10a836251d9 100644 --- a/src/scripting/push_check.hpp +++ b/src/scripting/push_check.hpp @@ -93,13 +93,13 @@ namespace lua_check_impl std::enable_if_t, std::string> lua_check(lua_State *L, int n) { - return luaL_checkstring(L, n); + return std::string(luaW_tostring(L, n)); } template std::enable_if_t, 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 std::enable_if_t, void>