fix document global for external Lua scripts in designer and Android
This commit is contained in:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user