Reputation: 65
I have this lua script:
local set = {}
set.name = "DebugMenu"
set.setName = "DebugMenu"
set.descriptionFilenameOverride = ""
set.logicalName = "<DebugMenu>"
In java I have:
LuaValue script = globals.load(..input stream.., "main", "t", globals);
How do I access the values in the table in the lua script?
Upvotes: 0
Views: 258
Reputation: 2147
You could rename it local_set
instead, just so there's no confusion with the half-a-dozen or so other set
functions (sethook, setmetatable...) that reside in _G. Then drop that local
, so you can access contents from global scope.
https://pgl.yoyo.org/luai/i/debug.getlocal The possibility exists, but it's wonky. https://www.lua.org/pil/23.1.1.html You'd have to scroll through keys 'till you find it.
local stack_level = 1
local stack_index = 1
while true do
local name, value = debug.getlocal( stack_level, stack_index )
print()
if not name then break end
if type( value ) == 'table' then
for k, v in pairs( value ) do
print( k, v, type(v) )
end
else -- could be recursive, if you need to dig deeper
print( name, value, type(value) )
end
stack_index = stack_index +1
end
Edit:
Seems easier just to rename it, so it's safely accessible from within your globals.
local_set = {}
local_set .name = 'DebugMenu'
local_set .setName = 'DebugMenu'
local_set .descriptionFilenameOverride = ''
local_set .logicalName = '<DebugMenu>'
Upvotes: 0