summaryrefslogtreecommitdiff
path: root/libs/lua
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-03-22 16:59:02 +0100
committerRobin Gareus <robin@gareus.org>2017-03-22 16:59:02 +0100
commit4a180e68ba86ae1b2774879a95e89a236cd87e50 (patch)
tree2726a2d713ad9f29b5b75c13e48ab4fa2308845e /libs/lua
parent35dcd46d7de2755be15b4fef51044094ba38eee2 (diff)
Special case const std::string& Lua binding.
since 6dc3bdf, a const string reference would leave scope with Lua code fn("text") calling a C++ fn (const std::string&) before the C++ function is called.
Diffstat (limited to 'libs/lua')
-rw-r--r--libs/lua/LuaBridge/detail/Stack.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/libs/lua/LuaBridge/detail/Stack.h b/libs/lua/LuaBridge/detail/Stack.h
index e6ff637f19..7311c921f9 100644
--- a/libs/lua/LuaBridge/detail/Stack.h
+++ b/libs/lua/LuaBridge/detail/Stack.h
@@ -731,14 +731,15 @@ struct Stack <std::string const&>
{
static inline void push (lua_State* L, std::string const& str)
{
- lua_pushstring (L, str.c_str());
+ lua_pushlstring (L, str.c_str (), str.size());
}
- static inline std::string get (lua_State* L, int index)
+ static inline std::string& get (lua_State* L, int index)
{
size_t len;
const char *str = luaL_checklstring(L, index, &len);
- return std::string (str, len);
+ std::string* x = new (lua_newuserdata (L, sizeof (std::string))) std::string (str, len);
+ return *x;
}
};