Added require instead of run file.
This commit is contained in:
parent
3b10a60826
commit
b1b36fead5
@ -1,4 +1,4 @@
|
|||||||
run file "lib/core.nom"
|
require "lib/core.nom"
|
||||||
|
|
||||||
test: say "foo" ..yields ".."
|
test: say "foo" ..yields ".."
|
||||||
|Call [say %]:
|
|Call [say %]:
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
start with a #.. and
|
start with a #.. and
|
||||||
continue until dedent
|
continue until dedent
|
||||||
|
|
||||||
run file "lib/core.nom"
|
require "lib/core.nom"
|
||||||
|
|
||||||
say "foo"
|
say "foo"
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
run file "lib/core.nom"
|
require "lib/core.nom"
|
||||||
run file "lib/secrets.nom"
|
require "lib/secrets.nom"
|
||||||
run file "lib/plurals.nom"
|
require "lib/plurals.nom"
|
||||||
|
|
||||||
|
|
||||||
# Users:
|
# Users:
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
continue until dedent
|
continue until dedent
|
||||||
|
|
||||||
# Import files like so:
|
# Import files like so:
|
||||||
run file "core.nom"
|
require "core.nom"
|
||||||
|
|
||||||
# Numbers:
|
# Numbers:
|
||||||
23
|
23
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
run file "lib/secrets.nom"
|
require "lib/core.nom"
|
||||||
|
require "lib/secrets.nom"
|
||||||
|
|
||||||
# Plurals
|
# Plurals
|
||||||
with secrets:
|
with secrets:
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require "lib/core.nom"
|
||||||
|
|
||||||
macro block: with secrets %block
|
macro block: with secrets %block
|
||||||
..=: ".."
|
..=: ".."
|
||||||
|local secrets = {}
|
|local secrets = {}
|
||||||
|
@ -816,6 +816,13 @@ do
|
|||||||
})
|
})
|
||||||
return self:tree_to_value(vars.lua_code, inner_vars)
|
return self:tree_to_value(vars.lua_code, inner_vars)
|
||||||
end)
|
end)
|
||||||
|
self:def("require %filename", function(self, vars)
|
||||||
|
if not self.loaded_files[vars.filename] then
|
||||||
|
local file = io.open(vars.filename)
|
||||||
|
self.loaded_files[vars.filename] = self:run(file:read('*a'))
|
||||||
|
end
|
||||||
|
return self.loaded_files[vars.filename]
|
||||||
|
end)
|
||||||
return self:def("run file %filename", function(self, vars)
|
return self:def("run file %filename", function(self, vars)
|
||||||
local file = io.open(vars.filename)
|
local file = io.open(vars.filename)
|
||||||
return self:run(file:read('*a'))
|
return self:run(file:read('*a'))
|
||||||
@ -835,6 +842,7 @@ do
|
|||||||
return io.write(...)
|
return io.write(...)
|
||||||
end
|
end
|
||||||
self.utils = utils
|
self.utils = utils
|
||||||
|
self.loaded_files = { }
|
||||||
end,
|
end,
|
||||||
__base = _base_0,
|
__base = _base_0,
|
||||||
__name = "NomsuCompiler"
|
__name = "NomsuCompiler"
|
||||||
|
@ -99,6 +99,7 @@ class NomsuCompiler
|
|||||||
@initialize_core!
|
@initialize_core!
|
||||||
@write = (...)=> io.write(...)
|
@write = (...)=> io.write(...)
|
||||||
@utils = utils
|
@utils = utils
|
||||||
|
@loaded_files = {}
|
||||||
|
|
||||||
writeln:(...)=>
|
writeln:(...)=>
|
||||||
@write(...)
|
@write(...)
|
||||||
@ -593,6 +594,12 @@ class NomsuCompiler
|
|||||||
inner_vars = setmetatable({}, {__index:(_,key)-> "vars[#{utils.repr(key,true)}]"})
|
inner_vars = setmetatable({}, {__index:(_,key)-> "vars[#{utils.repr(key,true)}]"})
|
||||||
return @tree_to_value(vars.lua_code, inner_vars)
|
return @tree_to_value(vars.lua_code, inner_vars)
|
||||||
|
|
||||||
|
@def "require %filename", (vars)=>
|
||||||
|
if not @loaded_files[vars.filename]
|
||||||
|
file = io.open(vars.filename)
|
||||||
|
@loaded_files[vars.filename] = @run(file\read('*a'))
|
||||||
|
return @loaded_files[vars.filename]
|
||||||
|
|
||||||
@def "run file %filename", (vars)=>
|
@def "run file %filename", (vars)=>
|
||||||
file = io.open(vars.filename)
|
file = io.open(vars.filename)
|
||||||
return @run(file\read('*a'))
|
return @run(file\read('*a'))
|
||||||
|
Loading…
Reference in New Issue
Block a user