Files
lovedos/src/main.c

73 lines
1.4 KiB
C
Raw Normal View History

/**
2016-09-22 19:30:56 +01:00
* Copyright (c) 2016 rxi
2014-06-13 21:01:19 +01:00
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MIT license. See LICENSE for details.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include "lib/dmt/dmt.h"
#include "vga.h"
#include "luaobj.h"
#include "keyboard.h"
2016-09-29 19:22:29 +01:00
#include "filesystem.h"
#include "mouse.h"
2014-06-13 21:01:19 +01:00
#include "image.h"
#include "palette.h"
2014-06-13 21:01:19 +01:00
static lua_State *L;
static void deinit(void) {
/* Deinit and clear up everything. Called at exit */
vga_deinit();
keyboard_deinit();
lua_close(L);
2016-09-29 19:22:29 +01:00
filesystem_deinit();
2014-06-13 21:01:19 +01:00
dmt_dump(stdout);
}
2016-09-29 19:22:29 +01:00
2014-06-14 16:27:42 +01:00
static int onLuaPanic(lua_State *L) {
vga_deinit();
const char *err = lua_tostring(L, -1);
printf("lua panic: %s\n", err);
return 0;
}
2014-06-13 21:01:19 +01:00
int luaopen_love(lua_State *L);
int main(void) {
/* Init everything */
atexit(deinit);
2016-09-29 19:22:29 +01:00
filesystem_mount("."); /* Mount cwd: temporary */
2014-06-13 21:01:19 +01:00
vga_init();
palette_init();
2014-06-13 21:01:19 +01:00
keyboard_init();
mouse_init();
2014-06-13 21:01:19 +01:00
/* Init lua */
L = luaL_newstate();
2014-06-14 16:27:42 +01:00
lua_atpanic(L, onLuaPanic);
2014-06-13 21:01:19 +01:00
luaL_openlibs(L);
luaL_requiref(L, "love", luaopen_love, 1);
#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)) {
2014-06-13 21:01:19 +01:00
vga_deinit();
const char *err = lua_tostring(L, -1);
printf("Error\n%s\n", err);
2014-06-13 21:01:19 +01:00
}
return 0;
}