fix document global for external Lua scripts in designer and Android

This commit is contained in:
2026-01-19 22:51:19 +01:00
parent a3a15b0644
commit 5de087e8e0
3 changed files with 40 additions and 32 deletions

View File

@@ -3,34 +3,11 @@
local results = {}
local logCounter = 0
local currentDocument = nil -- Cache the document reference
-- Helper to get document (try multiple methods)
-- Helper to get document (use global set by C++)
local function getDocument()
-- First try the cached document
if currentDocument then
return currentDocument
end
-- Try the global document
if document then
currentDocument = document
return document
end
-- Try to get from RmlUi context (our context is named "default")
if rmlui and rmlui.contexts then
-- Try both "default" and "main" context names
local ctx = rmlui.contexts["default"] or rmlui.contexts.main
if ctx and ctx.documents then
-- documents is a proxy, iterate to get first doc
for i, doc in ipairs(ctx.documents) do
if doc then
currentDocument = doc
return currentDocument
end
end
end
end
return nil
-- The C++ code sets 'document' global after loading
return document
end
local function log(msg)
@@ -241,10 +218,6 @@ function testStorage()
end
end
-- Initialize: cache the document when script loads
if document then
currentDocument = document
print("[LUA] Document cached on load")
end
-- Initialize
log("Sandbox Test App loaded")
log("Lua version: " .. (_VERSION or "unknown"))