#include <stdbool.h>
#include <stdio.h>
#include <lauxlib.h>
#include <lua.h>
#include <luaconf.h>
#include <lualib.h>
#include <psp2/kernel/processmgr.h>
#define MAIN_SCRIPT "main.lua"
int pmain(lua_State *L);
int main(int argc, char *argv[]) {
int status;
lua_State *L = luaL_newstate();
luaL_openlibs(L);
lua_pushcfunction(L, &pmain);
status = lua_pcall(L, 0, 0, 0);
if (status != LUA_OK)
printf("An error occured.\n");
lua_close(L);
return 0;
}
/* pmain
* Protected main (https://www.lua.org/pil/24.3.1.html)
*/
int pmain(lua_State *L) {
int status;
luaL_checkversion(L);
while (true) {
status = luaL_loadfile(L, MAIN_SCRIPT);
if (status == LUA_OK)
status = lua_pcall(L, 0, LUA_MULTRET, 0);
// Retry only if an error occured
if (status == LUA_OK)
break;
printf("Error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
// getchar();
}
return 0;
}