Improve lovr.filesystem.load errors;

Lua was happily compiling nil chunks and making them return empty
strings, which was not a good error experience in situations where
your file couldn't be loaded properly.  Now we return nil plus an
error message, which matches LOVE and other Lua conventions.
This commit is contained in:
bjorn 2020-02-22 00:30:30 -08:00
parent 3d3fb71a98
commit 2cf6d7b109
1 changed files with 5 additions and 0 deletions

View File

@ -59,6 +59,11 @@ static void pushDirectoryItem(void* context, const char* path) {
static int luax_loadfile(lua_State* L, const char* path, const char* debug) {
size_t size;
void* buffer = luax_readfile(path, &size);
if (!buffer) {
lua_pushnil(L);
lua_pushfstring(L, "Could not load file '%s'", path);
return 2;
}
int status = luaL_loadbuffer(L, buffer, size, debug);
free(buffer);
switch (status) {