From 1d23b7c1be5101c8465d141b56363d4b424d6b91 Mon Sep 17 00:00:00 2001 From: yzh Date: Wed, 14 Feb 2024 22:39:35 +0800 Subject: maybe fix the /run cmd --- source/game/scripting/StarLuaRoot.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source/game/scripting/StarLuaRoot.cpp') diff --git a/source/game/scripting/StarLuaRoot.cpp b/source/game/scripting/StarLuaRoot.cpp index fc205c0..d79e8f4 100644 --- a/source/game/scripting/StarLuaRoot.cpp +++ b/source/game/scripting/StarLuaRoot.cpp @@ -106,9 +106,11 @@ LuaContext LuaRoot::createContext(StringList const& scriptPaths) { } }); - newContext.set("loadstring", m_luaEngine->createFunction([&newContext](String const& source, Maybe const& name, Maybe const& env) -> LuaFunction { + auto handleIndex = newContext.handleIndex(); + auto engine = m_luaEngine.get(); + newContext.set("loadstring", m_luaEngine->createFunction([engine,handleIndex](String const& source, Maybe const& name, Maybe const& env) -> LuaFunction { String functionName = name ? strf("loadstring: {}", *name) : "loadstring"; - return newContext.engine().createFunctionFromSource(newContext.handleIndex(), source.utf8Ptr(), source.utf8Size(), functionName.utf8Ptr()); + return engine->createFunctionFromSource(handleIndex, source.utf8Ptr(), source.utf8Size(), functionName.utf8Ptr()); })); auto assets = Root::singleton().assets(); -- cgit v1.2.3