1
0
mirror of https://github.com/natnat-mc/moonbuild synced 2026-05-28 09:39:40 +02:00
Files
moonbuild/moonbuild/context.moon
T
Codinget c8670ab903 v2
2020-11-07 21:01:26 +01:00

39 lines
879 B
MoonScript

import runwithcontext from require 'moonbuild.compat.ctx'
topenv = require 'moonbuild.env.top'
initenv = require 'moonbuild.env.init'
import includes from require 'moonbuild._common'
import insert from table
class Context
new: =>
@targets = {}
@defaulttargets = {}
@variables = {}
@inits = {}
addvar: (var) =>
@variables[var.name] = var
addinit: (fn) =>
insert @inits, fn
addtarget: (target) =>
insert @targets, target
resetexecuted: =>
@executedtargets = {}
adddefault: (target) =>
error "not a target of the current context: #{target}" unless includes @targets, target
error "not a named target" unless (type target.name) == 'string'
insert @defaulttargets, target.name
load: (code, overrides) =>
runwithcontext code, (topenv @, overrides)
init: =>
if @inits[1]
env = (initenv @)
for init in *@inits
runwithcontext code, env