mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
parse/compile errors have better error messages
This commit is contained in:
parent
c3fd7812ce
commit
c344b8ca3a
11
bin/moon
11
bin/moon
@ -41,7 +41,16 @@ local new_arg = {
|
|||||||
select(ind + 1, unpack(arg))
|
select(ind + 1, unpack(arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
local chunk = moonscript.loadfile(script_fname)
|
local chunk
|
||||||
|
local passed, err = pcall(function()
|
||||||
|
chunk = moonscript.loadfile(script_fname)
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not passed then
|
||||||
|
print(err)
|
||||||
|
os.exit()
|
||||||
|
end
|
||||||
|
|
||||||
getfenv(chunk).arg = new_arg
|
getfenv(chunk).arg = new_arg
|
||||||
|
|
||||||
local runner = coroutine.create(chunk)
|
local runner = coroutine.create(chunk)
|
||||||
|
@ -27,7 +27,7 @@ to_lua = function(text)
|
|||||||
end
|
end
|
||||||
local tree, err = parse.string(text)
|
local tree, err = parse.string(text)
|
||||||
if not tree then
|
if not tree then
|
||||||
error("Parse error: " .. err, 2)
|
error(err, 2)
|
||||||
end
|
end
|
||||||
local code, ltable, pos = compile.tree(tree)
|
local code, ltable, pos = compile.tree(tree)
|
||||||
if not code then
|
if not code then
|
||||||
@ -65,7 +65,12 @@ if not _G.moon_no_loader then
|
|||||||
init_loader()
|
init_loader()
|
||||||
end
|
end
|
||||||
loadstring = function(str, chunk_name)
|
loadstring = function(str, chunk_name)
|
||||||
local code, ltable = to_lua(str)
|
local passed, code, ltable = pcall(function()
|
||||||
|
return to_lua(str)
|
||||||
|
end)
|
||||||
|
if not passed then
|
||||||
|
error(chunk_name .. ": " .. code, 2)
|
||||||
|
end
|
||||||
if chunk_name then
|
if chunk_name then
|
||||||
line_tables[chunk_name] = ltable
|
line_tables[chunk_name] = ltable
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ to_lua = (text) ->
|
|||||||
|
|
||||||
tree, err = parse.string text
|
tree, err = parse.string text
|
||||||
if not tree
|
if not tree
|
||||||
error "Parse error: " .. err, 2
|
error err, 2
|
||||||
|
|
||||||
code, ltable, pos = compile.tree tree
|
code, ltable, pos = compile.tree tree
|
||||||
if not code
|
if not code
|
||||||
@ -63,7 +63,10 @@ init_loader = ->
|
|||||||
init_loader! if not _G.moon_no_loader
|
init_loader! if not _G.moon_no_loader
|
||||||
|
|
||||||
loadstring = (str, chunk_name) ->
|
loadstring = (str, chunk_name) ->
|
||||||
code, ltable = to_lua str
|
passed, code, ltable = pcall -> to_lua str
|
||||||
|
if not passed
|
||||||
|
error chunk_name .. ": " .. code, 2
|
||||||
|
|
||||||
line_tables[chunk_name] = ltable if chunk_name
|
line_tables[chunk_name] = ltable if chunk_name
|
||||||
lua.loadstring code, chunk_name or "=(moonscript.loadstring)"
|
lua.loadstring code, chunk_name or "=(moonscript.loadstring)"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user