1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Cleaned initialisation process

This commit is contained in:
Reuh 2015-08-22 20:37:45 +02:00
parent 8da0e47ae3
commit 0af33d0b3a
6 changed files with 70 additions and 58 deletions

View file

@ -1,6 +1,4 @@
#include <3ds.h>
#include <sf2d.h>
#include <sftd.h>
#include <lua.h>
#include <lauxlib.h>
@ -8,15 +6,14 @@
#define BOOT_FILE "sdmc:/3ds/ctruLua/main.lua"
int load_ctr_lib(lua_State *L);
void unload_font_lib();
void unload_fs_lib();
void load_ctr_lib(lua_State *L);
void unload_ctr_lib(lua_State *L);
bool gfxinit = false;
bool isGfxInitialised;
// Display an error
void error(const char *error) {
if (!gfxinit) gfxInitDefault();
if (!isGfxInitialised) gfxInitDefault();
gfxSet3D(false);
consoleInit(GFX_TOP, NULL);
@ -33,7 +30,7 @@ void error(const char *error) {
gspWaitForVBlank();
}
if (!gfxinit) gfxExit();
if (!isGfxInitialised) gfxExit();
}
// Main loop
@ -44,16 +41,6 @@ int main() {
error("Memory allocation error while creating a new Lua state");
return 0;
}
// Init GFX
sf2d_init();
sftd_init();
gfxinit = true;
// Init accel/gyro
HIDUSER_EnableAccelerometer();
HIDUSER_EnableGyroscope();
// Load libs
luaL_openlibs(L);
@ -62,20 +49,11 @@ int main() {
// Do the actual thing
if (luaL_dofile(L, BOOT_FILE)) error(luaL_checkstring(L, -1));
// Unload libs
unload_ctr_lib(L);
// Unload Lua
lua_close(L);
// Unload libs
unload_font_lib();
unload_fs_lib();
// Disable accel/gyro
HIDUSER_DisableAccelerometer();
HIDUSER_DisableGyroscope();
// Uninit GFX
sftd_fini();
sf2d_fini();
return 0;
}