Even cleaner support for __src__
This commit is contained in:
parent
96441251c4
commit
ab9af11ec3
@ -210,6 +210,7 @@ class NomsuCompiler
|
|||||||
setmetatable(@defs["#vars"], {__index:parent["#vars"]})
|
setmetatable(@defs["#vars"], {__index:parent["#vars"]})
|
||||||
setmetatable(@defs["#loaded_files"], {__index:parent["#loaded_files"]})
|
setmetatable(@defs["#loaded_files"], {__index:parent["#loaded_files"]})
|
||||||
@callstack = {}
|
@callstack = {}
|
||||||
|
@macrostack = {}
|
||||||
@debug = false
|
@debug = false
|
||||||
@utils = utils
|
@utils = utils
|
||||||
@repr = (...)=> repr(...)
|
@repr = (...)=> repr(...)
|
||||||
@ -332,9 +333,11 @@ class NomsuCompiler
|
|||||||
@write "#{colored.bright "RUNNING MACRO"} #{colored.underscore colored.magenta(tree.stub)} "
|
@write "#{colored.bright "RUNNING MACRO"} #{colored.underscore colored.magenta(tree.stub)} "
|
||||||
@writeln "#{colored.bright "WITH ARGS:"} #{colored.dim repr args}"
|
@writeln "#{colored.bright "WITH ARGS:"} #{colored.dim repr args}"
|
||||||
insert @callstack, "#macro"
|
insert @callstack, "#macro"
|
||||||
|
insert @macrostack, tree
|
||||||
old_tree, @defs["#macro_tree"] = @defs["#macro_tree"], tree
|
old_tree, @defs["#macro_tree"] = @defs["#macro_tree"], tree
|
||||||
expr, statement = @call(tree.stub, tree.line_no, unpack(args))
|
expr, statement = @call(tree.stub, tree.line_no, unpack(args))
|
||||||
@defs["#macro_tree"] = old_tree
|
@defs["#macro_tree"] = old_tree
|
||||||
|
remove @macrostack
|
||||||
remove @callstack
|
remove @callstack
|
||||||
return expr, statement
|
return expr, statement
|
||||||
|
|
||||||
@ -828,8 +831,6 @@ end)]])\format(concat(lua_bits, "\n"))
|
|||||||
for bit in *code.value
|
for bit in *code.value
|
||||||
if type(bit) == "string"
|
if type(bit) == "string"
|
||||||
insert concat_parts, bit
|
insert concat_parts, bit
|
||||||
elseif bit.src == '__src__'
|
|
||||||
insert concat_parts, repr(@dedent @defs["#macro_tree"].src)
|
|
||||||
else
|
else
|
||||||
expr, statement = @tree_to_lua bit, filename
|
expr, statement = @tree_to_lua bit, filename
|
||||||
if statement
|
if statement
|
||||||
@ -848,6 +849,8 @@ end)]])\format(concat(lua_bits, "\n"))
|
|||||||
return lua, nil
|
return lua, nil
|
||||||
@defmacro "=lua %code", lua_value
|
@defmacro "=lua %code", lua_value
|
||||||
|
|
||||||
|
@defmacro "__src__", => @repr @dedent @macrostack[#@macrostack-1].src
|
||||||
|
|
||||||
run_file = (vars)=>
|
run_file = (vars)=>
|
||||||
if vars.filename\match(".*%.lua")
|
if vars.filename\match(".*%.lua")
|
||||||
return dofile(vars.filename)(@, vars)
|
return dofile(vars.filename)(@, vars)
|
||||||
|
Loading…
Reference in New Issue
Block a user