mirror of https://github.com/bjornbytes/lovr.git
Improve error messages;
This commit is contained in:
parent
10ddc06c13
commit
1061134800
|
@ -47,10 +47,10 @@ static int filesystemLoader(lua_State* L) {
|
|||
};
|
||||
|
||||
for (size_t i = 0; i < sizeof(requirePath) / sizeof(char*); i++) {
|
||||
char filename[256];
|
||||
char filename[LOVR_PATH_MAX];
|
||||
char* sub = strchr(requirePath[i], '?');
|
||||
|
||||
memset(filename, 0, 256);
|
||||
memset(filename, 0, LOVR_PATH_MAX);
|
||||
|
||||
if (sub) {
|
||||
int index = (int) (sub - requirePath[i]);
|
||||
|
@ -61,9 +61,12 @@ static int filesystemLoader(lua_State* L) {
|
|||
if (lovrFilesystemIsFile(filename)) {
|
||||
size_t size;
|
||||
void* data = lovrFilesystemRead(filename, &size);
|
||||
char identifier[LOVR_PATH_MAX + 1];
|
||||
strncpy(identifier, "@", 2);
|
||||
strncat(identifier, filename, LOVR_PATH_MAX);
|
||||
|
||||
if (data) {
|
||||
if (!luaL_loadbuffer(L, data, size, filename)) {
|
||||
if (!luaL_loadbuffer(L, data, size, identifier)) {
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
|
|
26
src/lovr.c
26
src/lovr.c
|
@ -22,6 +22,18 @@ static int getStackTrace(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void handleError(lua_State* L, const char* message) {
|
||||
lua_getglobal(L, "lovr");
|
||||
lua_getfield(L, -1, "errhand");
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushstring(L, message);
|
||||
lua_pcall(L, 1, 0, 0);
|
||||
} else {
|
||||
error(message);
|
||||
}
|
||||
lovrDestroy(1);
|
||||
}
|
||||
|
||||
static int lovrGetOS(lua_State* L) {
|
||||
#ifdef _WIN32
|
||||
lua_pushstring(L, "Windows");
|
||||
|
@ -98,8 +110,7 @@ void lovrInit(lua_State* L, int argc, char** argv) {
|
|||
luax_preloadmodule(L, "json", luaopen_cjson);
|
||||
|
||||
if (luaL_loadbuffer(L, (const char*) boot_lua, boot_lua_len, "boot.lua") || lua_pcall(L, 0, 0, 0)) {
|
||||
const char* message = luaL_checkstring(L, 1);
|
||||
error("Unable to bootstrap LOVR: %s", message);
|
||||
handleError(L, lua_tostring(L, -1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,16 +157,7 @@ void lovrRun(lua_State* L) {
|
|||
lua_getglobal(L, "lovr");
|
||||
lua_getfield(L, -1, "run");
|
||||
if (lua_pcall(L, 0, 1, -3)) {
|
||||
lua_getfield(L, -2, "errhand");
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushvalue(L, -2);
|
||||
if (!lua_pcall(L, 1, 0, 0)) {
|
||||
lovrDestroy(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
error(lua_tostring(L, -2));
|
||||
handleError(L, lua_tostring(L, -1));
|
||||
}
|
||||
|
||||
// Exit with return value from lovr.run
|
||||
|
|
Loading…
Reference in New Issue