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

summaryrefslogtreecommitdiff
path: root/source/core/StarLua.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-11-30 09:17:44 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-11-30 09:17:44 +1100
commitcbde26aebeec3a3cb72cfd6b55c7867d27b8c789 (patch)
treea25dc6c01637d1ce2049280f1cb67c69f584955d /source/core/StarLua.cpp
parente437282d5cf33b01b967151a56c70d8d1603f375 (diff)
move loadstring out of LuaRoot
Diffstat (limited to 'source/core/StarLua.cpp')
-rw-r--r--source/core/StarLua.cpp10
1 files changed, 9 insertions, 1 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) {