Fix loader bugs
This commit is contained in:
parent
3cb93d4aeb
commit
238cdd7192
@ -23,7 +23,6 @@ function raylua.repl()
|
||||
while true do
|
||||
io.write "> "
|
||||
local line = io.read "l"
|
||||
|
||||
local f, err = loadstring(line)
|
||||
|
||||
if f then
|
||||
@ -43,18 +42,19 @@ if raylua.loadfile then
|
||||
-- Change the second loader to load files using raylua.loadfile
|
||||
package.loaders[2] = function (name)
|
||||
for path in package.path:gmatch "([^;]+);?" do
|
||||
name = name:gsub("%.", "/")
|
||||
path = path:gsub("?", name)
|
||||
|
||||
local content, err = raylua.loadfile(path)
|
||||
if content then
|
||||
local f, err = load(content)
|
||||
local f, err = load(content, path)
|
||||
assert(f, err)
|
||||
|
||||
return f
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
return
|
||||
end
|
||||
|
||||
print "[RAYLUA] Load main.lua from payload."
|
||||
@ -67,7 +67,7 @@ if raylua.loadfile then
|
||||
end
|
||||
|
||||
if arg[1] then
|
||||
dofile()
|
||||
dofile(arg[1])
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -38,23 +38,23 @@ int raylua_loadfile(lua_State *L)
|
||||
|
||||
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
|
||||
if (index == -1) {
|
||||
lua_pushfstring(L, "%s: File not found.", path);
|
||||
lua_pushnil(L);
|
||||
lua_pushfstring(L, "%s: File not found.", path);
|
||||
return 2;
|
||||
}
|
||||
|
||||
mz_zip_archive_file_stat 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_pushfstring(L, "%s: Can't get file information.", path);
|
||||
return 2;
|
||||
}
|
||||
|
||||
size_t size = stat.m_uncomp_size;
|
||||
char *buffer = malloc(size + 1);
|
||||
if (buffer == NULL) {
|
||||
lua_pushfstring(L, "%s: Can't allocate file buffer.", path);
|
||||
lua_pushnil(L);
|
||||
lua_pushfstring(L, "%s: Can't allocate file buffer.", path);
|
||||
return 2;
|
||||
}
|
||||
buffer[size] = '\0';
|
||||
|
Loading…
Reference in New Issue
Block a user