parse/compile errors have better error messages

This commit is contained in:
leaf corcoran 2011-11-04 18:10:16 -07:00
parent c3fd7812ce
commit c344b8ca3a
3 changed files with 22 additions and 5 deletions

View File

@ -41,7 +41,16 @@ local new_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
local runner = coroutine.create(chunk)

View File

@ -27,7 +27,7 @@ to_lua = function(text)
end
local tree, err = parse.string(text)
if not tree then
error("Parse error: " .. err, 2)
error(err, 2)
end
local code, ltable, pos = compile.tree(tree)
if not code then
@ -65,7 +65,12 @@ if not _G.moon_no_loader then
init_loader()
end
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
line_tables[chunk_name] = ltable
end

View File

@ -31,7 +31,7 @@ to_lua = (text) ->
tree, err = parse.string text
if not tree
error "Parse error: " .. err, 2
error err, 2
code, ltable, pos = compile.tree tree
if not code
@ -63,7 +63,10 @@ init_loader = ->
init_loader! if not _G.moon_no_loader
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
lua.loadstring code, chunk_name or "=(moonscript.loadstring)"