Reverted "use %" to expr-like behavior with return values preserved.

This commit is contained in:
Bruce Hill 2018-02-05 15:09:44 -08:00
parent e8f9ef36d6
commit f58dc0fcb7
2 changed files with 6 additions and 4 deletions

View File

@ -1352,13 +1352,15 @@ do
}
end)
self:define_action("run file %filename", get_line_no(), function(_filename)
return nomsu:run_file(_filename)
return {
expr = "nomsu:run_file(" .. tostring(nomsu:tree_to_lua(filename).expr) .. ")"
}
end)
return self:define_compile_action("use %filename", get_line_no(), function(_filename)
local filename = nomsu:tree_to_value(_filename)
nomsu:require_file(filename)
return {
statements = "nomsu:require_file(" .. tostring(repr(filename)) .. ");"
expr = "nomsu:require_file(" .. tostring(repr(filename)) .. ");"
}
end)
end

View File

@ -929,12 +929,12 @@ class NomsuCompiler
return expr: repr("#{tree.filename}:#{tree.start},#{tree.stop}")
@define_action "run file %filename", get_line_no!, (_filename)->
nomsu\run_file(_filename)
return expr:"nomsu:run_file(#{nomsu\tree_to_lua(filename).expr})"
@define_compile_action "use %filename", get_line_no!, (_filename)->
filename = nomsu\tree_to_value(_filename)
nomsu\require_file(filename)
return statements:"nomsu:require_file(#{repr filename});"
return expr:"nomsu:require_file(#{repr filename});"
-- Only run this code if this file was run directly with command line arguments, and not require()'d:
if arg and debug.getinfo(2).func != require