Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/core/StarLua.cpp10
-rw-r--r--source/game/scripting/StarLuaRoot.cpp7
2 files changed, 9 insertions, 8 deletions
diff --git a/source/core/StarLua.cpp b/source/core/StarLua.cpp
index 5a2effa..91aebab 100644
--- a/source/core/StarLua.cpp
+++ b/source/core/StarLua.cpp
@@ -537,8 +537,16 @@ LuaContext LuaEngine::createContext() {
LuaDetail::shallowCopy(m_state, -1, -2);
lua_pop(m_state, 1);
+ auto context = LuaContext(LuaDetail::LuaHandle(RefPtr<LuaEngine>(this), popHandle(m_state)));
+ // Add loadstring
+ auto handleIndex = context.handleIndex();
+ context.set("loadstring", createFunction([this, handleIndex](String const& source, Maybe<String> const& name, Maybe<LuaTable> const& env) -> LuaFunction {
+ String functionName = name ? strf("loadstring: {}", *name) : "loadstring";
+ return createFunctionFromSource(env ? env->handleIndex() : handleIndex, source.utf8Ptr(), source.utf8Size(), functionName.utf8Ptr());
+ }));
+
// Then set that environment as the new context environment in the registry.
- return LuaContext(LuaDetail::LuaHandle(RefPtr<LuaEngine>(this), popHandle(m_state)));
+ return context;
}
void LuaEngine::collectGarbage(Maybe<unsigned> steps) {
diff --git a/source/game/scripting/StarLuaRoot.cpp b/source/game/scripting/StarLuaRoot.cpp
index a14d10a..592c24b 100644
--- a/source/game/scripting/StarLuaRoot.cpp
+++ b/source/game/scripting/StarLuaRoot.cpp
@@ -106,13 +106,6 @@ LuaContext LuaRoot::createContext(StringList const& scriptPaths) {
}
});
- auto handleIndex = newContext.handleIndex();
- auto engine = m_luaEngine.get();
- newContext.set("loadstring", m_luaEngine->createFunction([engine, handleIndex](String const& source, Maybe<String> const& name, Maybe<LuaTable> const& env) -> LuaFunction {
- String functionName = name ? strf("loadstring: {}", *name) : "loadstring";
- return engine->createFunctionFromSource(env ? env->handleIndex() : handleIndex, source.utf8Ptr(), source.utf8Size(), functionName.utf8Ptr());
- }));
-
auto assets = Root::singleton().assets();
for (auto const& scriptPath : scriptPaths) {