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:
V N 2018-01-14 14:48:44 +03:00 committed by Charles Dang
parent ba8aa80af8
commit 5209271db3

View file

@ -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 = {