A compromise between the speed of make and the ease of use of a build script
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
moonbuild/moonbuild/env/init.moon

32 lines
723 B

Target = require 'moonbuild.core.Target'
Variable = require 'moonbuild.core.Variable'
_ = require 'moonbuild._'
import flatten from _
(ctx) ->
varlayer = setmetatable {},
__index: _G
for name, var in pairs ctx.variables
rawset varlayer, name, var.value
env = setmetatable {},
__index: varlayer
__newindex: (k) => error "attempt to assign to global variable '#{k}', use the function 'var' instead"
rawset env, '_', _
rawset env, '_G', env
rawset env, '_ENV', env
rawset env, 'var', (name, ...) ->
var = Variable name, ...
ctx\addvar var
rawset varlayer, name, var.value
var
rawset env, 'target', (name, opts) ->
target = Target ctx, name, opts
ctx\addtarget target
target
env, varlayer