Fix loader bugs

This commit is contained in:
TSnake41 2020-03-25 22:51:30 +01:00
parent 3cb93d4aeb
commit 238cdd7192
2 changed files with 7 additions and 7 deletions

View File

@ -23,7 +23,6 @@ function raylua.repl()
while true do while true do
io.write "> " io.write "> "
local line = io.read "l" local line = io.read "l"
local f, err = loadstring(line) local f, err = loadstring(line)
if f then if f then
@ -43,18 +42,19 @@ if raylua.loadfile then
-- Change the second loader to load files using raylua.loadfile -- Change the second loader to load files using raylua.loadfile
package.loaders[2] = function (name) package.loaders[2] = function (name)
for path in package.path:gmatch "([^;]+);?" do for path in package.path:gmatch "([^;]+);?" do
name = name:gsub("%.", "/")
path = path:gsub("?", name) path = path:gsub("?", name)
local content, err = raylua.loadfile(path) local content, err = raylua.loadfile(path)
if content then if content then
local f, err = load(content) local f, err = load(content, path)
assert(f, err) assert(f, err)
return f return f
end end
end end
return nil return
end end
print "[RAYLUA] Load main.lua from payload." print "[RAYLUA] Load main.lua from payload."
@ -67,7 +67,7 @@ if raylua.loadfile then
end end
if arg[1] then if arg[1] then
dofile() dofile(arg[1])
return return
end end

View File

@ -38,23 +38,23 @@ int raylua_loadfile(lua_State *L)
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0); int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
if (index == -1) { if (index == -1) {
lua_pushfstring(L, "%s: File not found.", path);
lua_pushnil(L); lua_pushnil(L);
lua_pushfstring(L, "%s: File not found.", path);
return 2; return 2;
} }
mz_zip_archive_file_stat stat; mz_zip_archive_file_stat stat;
if (!mz_zip_reader_file_stat(&zip_file, index, &stat)) { if (!mz_zip_reader_file_stat(&zip_file, index, &stat)) {
lua_pushfstring(L, "%s: Can't get file information.", path);
lua_pushnil(L); lua_pushnil(L);
lua_pushfstring(L, "%s: Can't get file information.", path);
return 2; return 2;
} }
size_t size = stat.m_uncomp_size; size_t size = stat.m_uncomp_size;
char *buffer = malloc(size + 1); char *buffer = malloc(size + 1);
if (buffer == NULL) { if (buffer == NULL) {
lua_pushfstring(L, "%s: Can't allocate file buffer.", path);
lua_pushnil(L); lua_pushnil(L);
lua_pushfstring(L, "%s: Can't allocate file buffer.", path);
return 2; return 2;
} }
buffer[size] = '\0'; buffer[size] = '\0';