Added proper mounting to boot.lua; added nogame state
Removed temporary "." mounting from main.c
This commit is contained in:
@@ -12,6 +12,23 @@ function love.boot()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Try to mount .exe file, then the first argument
|
||||
for i, v in ipairs { love.argv[1], love.argv[2] } do
|
||||
local mounted = love.filesystem.mount(v)
|
||||
if mounted then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Load main.lua or init `nogame` state
|
||||
if love.filesystem.isFile("main.lua") then
|
||||
require("main")
|
||||
else
|
||||
love.nogame()
|
||||
end
|
||||
|
||||
love.run()
|
||||
end
|
||||
|
||||
|
||||
@@ -87,5 +104,3 @@ end
|
||||
|
||||
|
||||
xpcall(love.boot, love.errhand)
|
||||
xpcall(function() require("main") end, love.errhand)
|
||||
xpcall(love.run, love.errhand)
|
||||
|
||||
40
src/embed/nogame.lua
Normal file
40
src/embed/nogame.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
function love.nogame()
|
||||
|
||||
function love.load()
|
||||
love.graphics.setBackgroundColor(228, 65, 68)
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
if key == "escape" then
|
||||
os.exit()
|
||||
end
|
||||
end
|
||||
|
||||
local function drawText(str, y)
|
||||
local screenw = love.graphics.getWidth()
|
||||
local font = love.graphics.getFont()
|
||||
love.graphics.print(str, (screenw - font:getWidth(str)) / 2, y)
|
||||
end
|
||||
|
||||
local function drawLines(ycenter, width, height)
|
||||
local screenw = love.graphics.getWidth()
|
||||
local n = 26
|
||||
for i = 0, n - 1 do
|
||||
local h = height * math.cos(i * 0.3 + love.timer.getTime() * 3) / 2
|
||||
local x = (screenw - width) / 2 + (i / (n - 1)) * width
|
||||
love.graphics.line(x, ycenter, x, ycenter + h)
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
love.graphics.setColor(255, 255, 255)
|
||||
drawText("LoveDOS " .. love.getVersion(), 62)
|
||||
drawLines(100, 120, 30)
|
||||
drawText("No game", 128)
|
||||
love.graphics.setColor(243, 150, 152)
|
||||
drawText("Press [ESCAPE] to quit", 184)
|
||||
end
|
||||
|
||||
end
|
||||
23
src/main.c
23
src/main.c
@@ -47,7 +47,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Init everything */
|
||||
atexit(deinit);
|
||||
filesystem_mount("."); /* Mount cwd: temporary */
|
||||
vga_init();
|
||||
palette_init();
|
||||
keyboard_init();
|
||||
@@ -73,13 +72,23 @@ int main(int argc, char **argv) {
|
||||
lua_pop(L, 1);
|
||||
|
||||
/* Init embedded scripts */
|
||||
#include "nogame_lua.h"
|
||||
#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();
|
||||
const char *err = lua_tostring(L, -1);
|
||||
printf("Error\n%s\n", err);
|
||||
struct {
|
||||
const char *name, *data; int size;
|
||||
} items[] = {
|
||||
{ "nogame.lua", nogame_lua, sizeof(nogame_lua) },
|
||||
{ "boot.lua", boot_lua, sizeof(boot_lua) },
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
int i;
|
||||
for (i = 0; items[i].name; i++) {
|
||||
int err = luaL_loadbuffer(L, items[i].data, items[i].size, items[i].name);
|
||||
if (err || lua_pcall(L, 0, 0, 0) != 0) {
|
||||
const char *str = lua_tostring(L, -1);
|
||||
fprintf(stderr, "Error: %s\n", str);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user