mirror of
				https://github.com/ctruLua/ctruLua.git
				synced 2025-10-27 16:39:29 +00:00 
			
		
		
		
	 bda9de4d1c
			
		
	
	
		bda9de4d1c
		
	
	
	
	
		
			
			Added libogg, libvorbis and libvorbisfile to 3ds_portlibs. You will need to compile thems using make build-portlibs. Opening OGG files works but they play badly. Added a very simple error handler in main.lua Added audio example. Renamed isGfxInitialised to isGfxInitialized. Did you know? The audio module is the longest ctrµLua module.
		
			
				
	
	
		
			57 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #include <3ds.h>
 | |
| 
 | |
| #include <lua.h>
 | |
| #include <lauxlib.h>
 | |
| #include <lualib.h>
 | |
| 
 | |
| void load_ctr_lib(lua_State *L);
 | |
| void unload_ctr_lib(lua_State *L);
 | |
| 
 | |
| bool isGfxInitialized;
 | |
| 
 | |
| // Display an error
 | |
| void error(const char *error) {
 | |
| 	if (!isGfxInitialized) gfxInitDefault();
 | |
| 	gfxSet3D(false);
 | |
| 
 | |
| 	consoleInit(GFX_TOP, NULL);
 | |
| 	printf("------------------ FATAL ERROR -------------------");
 | |
| 	printf(error);
 | |
| 	printf("\n--------------------------------------------------");
 | |
| 	printf("Please exit ctruLua by pressing start.");
 | |
| 	
 | |
| 	while (aptMainLoop()) {
 | |
| 		hidScanInput();
 | |
| 		if (hidKeysDown() & KEY_START) break;
 | |
| 		gfxFlushBuffers();
 | |
| 		gfxSwapBuffers();
 | |
| 		gspWaitForVBlank();
 | |
| 	}
 | |
| 
 | |
| 	if (!isGfxInitialized) gfxExit();
 | |
| }
 | |
| 
 | |
| // Main loop
 | |
| int main() {
 | |
| 	// Init Lua
 | |
| 	lua_State *L = luaL_newstate();
 | |
| 	if (L == NULL) {
 | |
| 		error("Memory allocation error while creating a new Lua state");
 | |
| 		return 0;
 | |
| 	}
 | |
| 
 | |
| 	// Load libs
 | |
| 	luaL_openlibs(L);
 | |
| 	load_ctr_lib(L);
 | |
| 
 | |
| 	// Do the actual thing
 | |
| 	if (luaL_dofile(L, "main.lua")) error(luaL_checkstring(L, -1));
 | |
| 
 | |
| 	// Unload libs
 | |
| 	unload_ctr_lib(L);
 | |
| 
 | |
| 	// Unload Lua
 | |
| 	lua_close(L);
 | |
| 
 | |
| 	return 0;
 | |
| }
 |