From 562b403a66a6a96d883620b27455564d50e3d49b Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 9 Jan 2013 11:47:16 +0100 Subject: Micro-optimizations for pushing strings to Lua Use lua_pushliteral and lua_pushlstring instead of lua_pushstring, which avoids Lua having to determine the length of the string. --- src/scripting/luautil.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/scripting/luautil.h') diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h index 0d2a981d..8e380d4e 100644 --- a/src/scripting/luautil.h +++ b/src/scripting/luautil.h @@ -102,7 +102,7 @@ public: mTypeName = typeName; luaL_newmetatable(s, mTypeName); // metatable - lua_pushstring(s, "__index"); // metatable, "__index" + lua_pushliteral(s, "__index"); // metatable, "__index" lua_createtable(s, 0, 0); // metatable, "__index", {} #if LUA_VERSION_NUM < 502 luaL_register(s, NULL, members); @@ -197,7 +197,7 @@ inline void push(lua_State *s, int val) inline void push(lua_State *s, const std::string &val) { - lua_pushstring(s, val.c_str()); + lua_pushlstring(s, val.c_str(), val.length()); } inline void push(lua_State *s, Entity *val) -- cgit v1.2.3-60-g2f50