added table syntax for var, closes #19

main v2.4.0
Codinget 4 years ago
parent ec5fc1cf7d
commit 803d1093bb
  1. 22
      Build.moon
  2. 12
      moonbuild/core/Variable.moon
  3. 2
      moonbuild/env/init.moon
  4. 20
      out/moonbuild.lua

@ -1,17 +1,17 @@
public var 'MOONC', 'moonc' public var MOONC: 'moonc'
public var 'AMALG', 'amalg.lua' public var AMALG: 'amalg.lua'
public var 'RM', 'rm', '-f', '--' public var RM: 'rm', '-f', '--'
public var 'LUA', 'lua5.3' public var LUA: 'lua5.3'
var 'LIB_SRC', _.wildcard 'moonbuild/**.moon' var LIB_SRC: _.wildcard 'moonbuild/**.moon'
var 'BIN_SRC', _.wildcard 'bin/*.moon' var BIN_SRC: _.wildcard 'bin/*.moon'
var 'LIB_LUA', _.patsubst LIB_SRC, '%.moon', '%.lua' var LIB_LUA: _.patsubst LIB_SRC, '%.moon', '%.lua'
var 'BIN_LUA', _.patsubst BIN_SRC, '%.moon', '%.lua' var BIN_LUA: _.patsubst BIN_SRC, '%.moon', '%.lua'
var 'BIN', _.patsubst BIN_LUA, 'bin/%.lua', 'out/%' var BIN: _.patsubst BIN_LUA, 'bin/%.lua', 'out/%'
var 'LIB', 'out/moonbuild.lua' var LIB: 'out/moonbuild.lua'
var 'MODULES', _.foreach (_.patsubst LIB_LUA, '%.lua', '%'), => @gsub '/', '.' var MODULES: _.foreach (_.patsubst LIB_LUA, '%.lua', '%'), => @gsub '/', '.'
with public default target 'all' with public default target 'all'
\after 'bin' \after 'bin'

@ -4,7 +4,17 @@ class Variable
new: (@name, ...) => new: (@name, ...) =>
@public = false @public = false
if (select '#', ...) !=1 or (type ...) == 'table' if (type @name) == 'table'
error "not a valid var table: #{next @name}" unless (type next @name) == 'string'
error "more than one var at once: #{next @name}, #{next @name, (next @name)}" if next @name, (next @name)
name = next @name
@name, param = name, @name
val = param[name]
if (select '#', ...) !=0 or (type val) == 'table'
@value = flatten val, ...
else
@value = val
elseif (select '#', ...) !=1 or (type ...) == 'table'
@value = flatten ... @value = flatten ...
else else
@value = ... @value = ...

@ -21,7 +21,7 @@ import flatten from _
rawset env, 'var', (name, ...) -> rawset env, 'var', (name, ...) ->
var = Variable name, ... var = Variable name, ...
ctx\addvar var ctx\addvar var
rawset varlayer, name, var.value rawset varlayer, var.name, var.value
var var
rawset env, 'target', (name, opts) -> rawset env, 'target', (name, opts) ->

@ -2227,7 +2227,23 @@ do
__init = function(self, name, ...) __init = function(self, name, ...)
self.name = name self.name = name
self.public = false 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(...) self.value = flatten(...)
else else
self.value = ... self.value = ...
@ -2545,7 +2561,7 @@ return function(ctx)
rawset(env, 'var', function(name, ...) rawset(env, 'var', function(name, ...)
local var = Variable(name, ...) local var = Variable(name, ...)
ctx:addvar(var) ctx:addvar(var)
rawset(varlayer, name, var.value) rawset(varlayer, var.name, var.value)
return var return var
end) end)
rawset(env, 'target', function(name, opts) rawset(env, 'target', function(name, opts)

Loading…
Cancel
Save