Getting a project to work with moonscript 0.5.0-1

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Getting a project to work with moonscript 0.5.0-1

Post 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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Getting a project to work with moonscript 0.5.0-1

Post 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.
User avatar
rozenmad
Prole
Posts: 9
Joined: Tue Jun 05, 2018 3:15 am

Re: Getting a project to work with moonscript 0.5.0-1

Post 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: :awesome:
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:
Attachments
moonscript.zip
(36.06 KiB) Downloaded 185 times
Post Reply

Who is online

Users browsing this forum: aikusuuta and 8 guests