1
0
mirror of https://github.com/natnat-mc/moonbuild synced 2026-05-11 19:51:15 +02:00

added table syntax for var, closes #19

This commit is contained in:
Codinget
2020-12-01 22:05:04 +01:00
parent ec5fc1cf7d
commit 803d1093bb
4 changed files with 41 additions and 15 deletions
+18 -2
View File
@@ -2227,7 +2227,23 @@ do
__init = function(self, name, ...)
self.name = name
self.public = false
if (select('#', ...)) ~= 1 or (type(...)) == 'table' then
if (type(self.name)) == 'table' then
if not ((type(next(self.name))) == 'string') then
error("not a valid var table: " .. tostring(next(self.name)))
end
if next(self.name, (next(self.name))) then
error("more than one var at once: " .. tostring(next(self.name)) .. ", " .. tostring(next(self.name, (next(self.name)))))
end
name = next(self.name)
local param
self.name, param = name, self.name
local val = param[name]
if (select('#', ...)) ~= 0 or (type(val)) == 'table' then
self.value = flatten(val, ...)
else
self.value = val
end
elseif (select('#', ...)) ~= 1 or (type(...)) == 'table' then
self.value = flatten(...)
else
self.value = ...
@@ -2545,7 +2561,7 @@ return function(ctx)
rawset(env, 'var', function(name, ...)
local var = Variable(name, ...)
ctx:addvar(var)
rawset(varlayer, name, var.value)
rawset(varlayer, var.name, var.value)
return var
end)
rawset(env, 'target', function(name, opts)