Skip to content

Instantly share code, notes, and snippets.

@gszr
Created May 30, 2025 16:09
Show Gist options
  • Save gszr/158dd237b6ac5781d888c457aff923db to your computer and use it in GitHub Desktop.
Save gszr/158dd237b6ac5781d888c457aff923db to your computer and use it in GitHub Desktop.
luarocks issue repro
function run_file(filename, env)
local fd, err = io.open(filename)
if not fd then
return nil, err, "open"
end
local str, err = fd:read("*a")
fd:close()
if not str then
return nil, err, "open"
end
str = str:gsub("^#![^\n]*\n", "")
local chunk, ran
if _VERSION == "Lua 5.1" then -- Lua 5.1
chunk, err = loadstring(str, filename)
if err then
print("ERROR: " .. (err or ""))
print(filename)
end
if chunk then
setfenv(chunk, env)
ran, err = pcall(chunk)
end
else -- Lua 5.2
chunk, err = load(str, filename, "t", env)
if chunk then
ran, err = pcall(chunk)
end
end
if not chunk then
return nil, "Error loading file: "..err, "load"
end
if not ran then
return nil, "Error running file: "..err, "run"
end
return true, err
end
local f = "manifest"
run_file(f, _G)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment