From 2cf6d7b10952b3d8f3070ae484d2e1d59d3118a8 Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 22 Feb 2020 00:30:30 -0800 Subject: [PATCH] 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. --- src/api/l_filesystem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/api/l_filesystem.c b/src/api/l_filesystem.c index 1d787edf..24f4ee7e 100644 --- a/src/api/l_filesystem.c +++ b/src/api/l_filesystem.c @@ -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) {