Moved embedded boot script from main.c to src/embed/boot.lua

This commit is contained in:
rxi
2016-09-29 20:06:43 +01:00
parent f30e2e2c54
commit 3fcaa3d86f
2 changed files with 66 additions and 68 deletions

View File

@@ -59,74 +59,8 @@ int main(void) {
luaL_openlibs(L);
luaL_requiref(L, "love", luaopen_love, 1);
const char boot[] =
"package.path = package.path .. ';' .. package.path:gsub('%?', 'lua/?')\n"
"local print = print\n"
"local xpcall = xpcall\n"
"function love.run()\n"
"if love.load then love.load() end\n"
"love.timer.step()\n"
"while true do\n"
/* Handle mouse events */
"for _, e in ipairs(love.mouse.poll()) do\n"
"if e.type == 'motion' then\n"
"if love.mousemoved then love.mousemoved(e.x, e.y, e.dx, e.dy) end\n"
"elseif e.type == 'pressed' then\n"
"if love.mousepressed then love.mousepressed(e.x, e.y, e.button) end\n"
"elseif e.type == 'released' then\n"
"if love.mousereleased then love.mousereleased(e.x, e.y, e.button) end\n"
"end\n"
"end\n"
/* Keyboard events */
"for _, e in ipairs(love.keyboard.poll()) do\n"
"if e.type == 'down' then\n"
"if love.keypressed then love.keypressed(e.key, e.code, e.isrepeat) end\n"
"elseif e.type == 'up' then\n"
"if love.keyreleased then love.keyreleased(e.key, e.code) end\n"
"elseif e.type == 'text' then\n"
"if love.textinput then love.textinput(e.text) end\n"
"end\n"
"end\n"
/* Update */
"love.timer.step()\n"
"local dt = love.timer.getDelta()\n"
"if love.update then love.update(dt) end\n"
/* Draw */
"love.graphics.clear()\n"
"if love.draw then love.draw() end\n"
"love.graphics.present()\n"
"end\n"
"end\n"
"function love.errhand(msg)\n"
/* Init error text */
"local err = { 'Error\\n', msg }\n"
"local trace = debug.traceback('', 2)\n"
"for line in string.gmatch(trace, '([^\\t]-)\\n') do\n"
"table.insert(err, line)\n"
"end\n"
"local str = table.concat(err, '\\n')"
/* Init error state */
"love.graphics.reset()\n"
"pcall(love.graphics.setBackgroundColor, 89, 157, 220)\n"
/* Do error main loop */
"while true do\n"
"for _, e in ipairs(love.keyboard.poll()) do\n"
"if e.type == 'down' and e.code == 1 then\n"
"os.exit()\n"
"end\n"
"end\n"
"love.graphics.clear()\n"
"love.graphics.print(str, 6, 6)\n"
"love.graphics.present()\n"
"end\n"
"end\n"
"xpcall(function() require('main') end, love.errhand)\n"
"xpcall(love.run, love.errhand)\n";
int err = luaL_loadbuffer(L, boot, sizeof(boot) - 1, "=boot");
#include "boot_lua.h"
int err = luaL_loadbuffer(L, boot_lua, sizeof(boot_lua) - 1, "boot.lua");
if (err || lua_pcall(L, 0, 0, 0)) {
vga_deinit();