Lua: add variables metatable
The implementation differs from already-existing wml.variable.proxy in that it does not try to proxy table sub-fields, and is fast & simple. Example usage: wml.variables.test = 123 print(wml.variables.test)
This commit is contained in:
parent
ba8aa80af8
commit
5209271db3
1 changed files with 9 additions and 0 deletions
|
@ -232,6 +232,15 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
|
|||
wml.variable.set = wesnoth.set_variable
|
||||
wml.variable.get_all = wesnoth.get_all_vars
|
||||
|
||||
wml.variables = setmetatable({}, {
|
||||
__index = function(_, key)
|
||||
return wesnoth.get_variable(key)
|
||||
end,
|
||||
__newindex = function(_, key, value)
|
||||
wesnoth.set_variable(key, value)
|
||||
end
|
||||
})
|
||||
|
||||
--[========[Variable Proxy Table]========]
|
||||
|
||||
local variable_mt = {
|
||||
|
|
Loading…
Add table
Reference in a new issue