Page 2 of 2
Re: Getting a project to work with moonscript 0.5.0-1
Posted: Mon May 21, 2018 1:04 pm
by bartbes
Looks like there is an api to convert errors back. When you use moonscript's loadstring it actually populates a translation table, so in your error handler you can call the rewrite_traceback function from
the moonscript.errors module.
Re: Getting a project to work with moonscript 0.5.0-1
Posted: Mon May 21, 2018 3:45 pm
by grump
bartbes wrote: ↑Mon May 21, 2018 1:04 pm
Looks like there is an api to convert errors back. When you use moonscript's loadstring it actually populates a translation table, so in your error handler you can call the rewrite_traceback function from
the moonscript.errors module.
Thanks for the hint.
rewrite_traceback returns nothing but nil. It utilizes io.open to accomplish its task, which will not work with the AppImage distribution because of the working directory problem. With a normal installation of LÖVE 0.10.2 it doesn't work either. It refuses to return anything and I can't figure out why. I assumed it might be because it can't parse backtraces with [string "(name)"], but gsub'ing the %[string "(.+)"%] away did not help.
I used
this code as a template for my bootstrapper.
I've given up on this for now.
Re: Getting a project to work with moonscript 0.5.0-1
Posted: Tue Jun 05, 2018 3:53 am
by rozenmad
I catch error from the Moonscript directly to LOVE, using this code. You may find it useful.
Code: Select all
assert(require("moonscript.init"))
local moonscript = assert(require "moonscript.base")
local util = assert(require "moonscript.util")
local errors = assert(require "moonscript.errors")
local iocb = assert(require "moonscript.iocb")
function iocb.read(filename)
return love.filesystem.read(filename)
end
local olderrhand = love.errhand
function love.errorhandler(msg)
local msg = tostring(msg)
local trace = debug.traceback("", 2)
msg = errors.rewrite_traceback(util.trim(trace), msg)
return olderrhand(msg)
end
local function assert_moonscript_error(...)
local msg = table.concat({...}, "\t")
assert(false, msg)
end
local moonscript_chunk, lua_parse_error
local passed, err = pcall(function()
moonscript_chunk, lua_parse_error = moonscript.loadfile("main.moon", { implicitly_return_root = false })
end)
if not passed then
assert_moonscript_error(err)
end
if not moonscript_chunk then
if lua_parse_error then
assert_moonscript_error(lua_parse_error)
else
assert_moonscript_error("Can't find file: " .. script_fname)
end
end
moonscript_chunk()
Update:
I succeeded to run moonscript files directly from the .love package, but I had to edit the moonscript source code for this.
Since the moonscript uses io.open, it does not have access to the .love package. I added moonscript.iocb to override the default io.open, see code above.
Fixed source moonscript to make it work: