mirror of https://github.com/bjornbytes/lovr.git
lovr.errhand;
This commit is contained in:
parent
bb9a4d8db7
commit
9c3e4ddec9
19
src/lovr.c
19
src/lovr.c
|
@ -65,6 +65,8 @@ void lovrInit(lua_State* L) {
|
|||
const char* message = luaL_checkstring(L, 1);
|
||||
error("Unable to bootstrap LOVR: %s", message);
|
||||
}
|
||||
|
||||
lua_atpanic(L, lovrOnLuaError);
|
||||
}
|
||||
|
||||
void lovrDestroy() {
|
||||
|
@ -87,7 +89,22 @@ void lovrRun(lua_State* L) {
|
|||
lua_call(L, 0, 0);
|
||||
}
|
||||
|
||||
void lovrOnError(int code, const char* description) {
|
||||
int lovrOnLuaError(lua_State* L) {
|
||||
const char* message = luaL_checkstring(L, -1);
|
||||
lua_getglobal(L, "lovr");
|
||||
lua_getfield(L, -1, "errhand");
|
||||
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushstring(L, message);
|
||||
lua_call(L, 1, 0);
|
||||
} else {
|
||||
error(message);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lovrOnGlfwError(int code, const char* description) {
|
||||
error(description);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
void lovrInit(lua_State* L);
|
||||
void lovrDestroy();
|
||||
void lovrRun(lua_State* L);
|
||||
void lovrOnError(int code, const char* description);
|
||||
int lovrOnLuaError(lua_State* L);
|
||||
void lovrOnGlfwError(int code, const char* description);
|
||||
void lovrOnClose(GLFWwindow* window);
|
||||
|
|
|
@ -7,7 +7,7 @@ int main(int argc, char* argv[]) {
|
|||
L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
initGlfw(lovrOnError, lovrOnClose);
|
||||
initGlfw(lovrOnGlfwError, lovrOnClose);
|
||||
lovrInit(L);
|
||||
lovrRun(L);
|
||||
|
||||
|
|
Loading…
Reference in New Issue