Skip to content

Instantly share code, notes, and snippets.

@losinggeneration
Last active October 13, 2016 15:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save losinggeneration/8407120 to your computer and use it in GitHub Desktop.
Save losinggeneration/8407120 to your computer and use it in GitHub Desktop.
A Löve2D main.lua bootstrap file for Moonscript. This loads main.moon during development so moonc isn't required. It also has the nice side effect of automatically being overwritten when moonc is run so the game is ready to be distributed.
--[[
DO NOT MAKE CHANGES TO THIS FILE!
This file will purposefully overwritten when moonc is run. However it provides
an easy way to do Moonscript development without having to use moonc to compile
to Lua.
]]--
--[[
License (MIT)
Copyright (C) 2013 by Leaf Corcoran
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
]]--
assert(require "luarocks.loader")
-- Below is basically the moon program which is shipped with Moonscript, thus the license
local moonscript = assert(require "moonscript")
local util = assert(require "moonscript.util")
local errors = assert(require "moonscript.errors")
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
local trace
xpcall(function() moonscript_chunk() end, function(e)
err = e
trace = debug.traceback("", 2)
end)
if err then
local truncated = errors.truncate_traceback(util.trim(trace))
local rewritten = errors.rewrite_traceback(truncated, err)
if rewritten then
assert_moonscript_error(rewritten)
else
assert_moonscript_error(table.concat({err, util.trim(trace)}, "\n"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment