aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-14 17:59:39 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-14 18:00:04 -0800
commitfb19d1af1155fa45a04b1f68b2254da551a3e780 (patch)
treea720c53706d86d4759d00728ff8e65f77bcb5860
parentce44ef96246d1b212c1ae936ce2fe0f5cd270711 (diff)
Fix for nomsu -v foo.lua, and made default nomsupath /opt/nomsu instead
of /opt
-rw-r--r--nomsu.lua38
-rwxr-xr-xnomsu.moon29
2 files changed, 39 insertions, 28 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 6f523c8..ff1e3fe 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -127,7 +127,7 @@ if NOMSU_VERSION and NOMSU_PREFIX then
else
add_path("./lib")
end
-local NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH or "/opt"
+local NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH or "/opt/nomsu"
add_path(NOMSU_PACKAGEPATH)
add_path(".")
package.nomsupath = table.concat(nomsupath, ";")
@@ -203,24 +203,30 @@ run = function()
print(("Compiled %-25s -> %s"):format(filename, filename:gsub("%.nom$", ".lua")))
output:close()
elseif args.verbose then
- local code = Files.read(filename)
- local source = Source(filename, 1, #code)
- code = NomsuCode:from(source, code)
local env = nomsu_environment.new_environment()
env.MODULE_NAME = filename
env.WAS_RUN_DIRECTLY = true
- local tree = env._1_parsed(code)
- if not (tree.type == 'FileChunks') then
- tree = {
- tree
- }
- end
- for chunk_no, chunk in ipairs(tree) do
- local lua = env:compile(chunk)
- lua:declare_locals()
- lua:prepend((chunk_no > 1) and '\n' or '', "-- File " .. tostring(filename) .. " chunk #" .. tostring(chunk_no) .. "\n")
- print(lua:text())
- env:run(lua)
+ local code = Files.read(filename)
+ local source = Source(filename, 1, #code)
+ if filename:match("%.lua$") then
+ code = LuaCode:from(Source(filename, 1, #code), code)
+ print(code:text())
+ env:run(code)
+ else
+ code = NomsuCode:from(source, code)
+ local tree = env._1_parsed(code)
+ if not (tree.type == 'FileChunks') then
+ tree = {
+ tree
+ }
+ end
+ for chunk_no, chunk in ipairs(tree) do
+ local lua = env:compile(chunk)
+ lua:declare_locals()
+ lua:prepend((chunk_no > 1) and '\n' or '', "-- File " .. tostring(filename) .. " chunk #" .. tostring(chunk_no) .. "\n")
+ print(lua:text())
+ env:run(lua)
+ end
end
else
local f = Files.read(filename)
diff --git a/nomsu.moon b/nomsu.moon
index 472bed5..fc2fe5a 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -104,7 +104,7 @@ if NOMSU_VERSION and NOMSU_PREFIX
add_path "#{NOMSU_PREFIX}/share/nomsu/#{NOMSU_VERSION}/lib"
else
add_path "./lib"
-NOMSU_PACKAGEPATH or= "/opt"
+NOMSU_PACKAGEPATH or= "/opt/nomsu"
add_path NOMSU_PACKAGEPATH
add_path "."
package.nomsupath = table.concat(nomsupath, ";")
@@ -161,20 +161,25 @@ run = ->
print ("Compiled %-25s -> %s")\format(filename, filename\gsub("%.nom$", ".lua"))
output\close!
elseif args.verbose
- code = Files.read(filename)
- source = Source(filename, 1, #code)
- code = NomsuCode\from(source, code)
env = nomsu_environment.new_environment!
env.MODULE_NAME = filename
env.WAS_RUN_DIRECTLY = true
- tree = env._1_parsed(code)
- tree = {tree} unless tree.type == 'FileChunks'
- for chunk_no, chunk in ipairs tree
- lua = env\compile(chunk)
- lua\declare_locals!
- lua\prepend((chunk_no > 1) and '\n' or '', "-- File #{filename} chunk ##{chunk_no}\n")
- print(lua\text!)
- env\run(lua)
+ code = Files.read(filename)
+ source = Source(filename, 1, #code)
+ if filename\match("%.lua$")
+ code = LuaCode\from(Source(filename, 1, #code), code)
+ print(code\text!)
+ env\run(code)
+ else
+ code = NomsuCode\from(source, code)
+ tree = env._1_parsed(code)
+ tree = {tree} unless tree.type == 'FileChunks'
+ for chunk_no, chunk in ipairs tree
+ lua = env\compile(chunk)
+ lua\declare_locals!
+ lua\prepend((chunk_no > 1) and '\n' or '', "-- File #{filename} chunk ##{chunk_no}\n")
+ print(lua\text!)
+ env\run(lua)
else
-- Just run the file
f = Files.read(filename)