mirror of https://github.com/bjornbytes/lovr.git
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:
parent
3d3fb71a98
commit
2cf6d7b109
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue