mirror of
https://github.com/mpv-player/mpv
synced 2025-02-03 05:31:34 +00:00
auto_profiles: fix compile_cond on lua 5.1
5.1's load() doesn't accept strings; loadstring must be used instead. In 5.2, loadstring is deprecated and setfenv is gone.
This commit is contained in:
parent
36e569b242
commit
df805cfc84
@ -136,16 +136,20 @@ setmetatable(p, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
local function compile_cond(name, s)
|
local function compile_cond(name, s)
|
||||||
-- (pre 5.2 ignores the extra arguments)
|
local code, chunkname = "return " .. s, "profile " .. name .. " condition"
|
||||||
local chunk, err = load("return " .. s, "profile " .. name .. " condition",
|
local chunk, err
|
||||||
"t", evil_magic)
|
if setfenv then -- lua 5.1
|
||||||
|
chunk, err = loadstring(code, chunkname)
|
||||||
|
if chunk then
|
||||||
|
setfenv(chunk, evil_magic)
|
||||||
|
end
|
||||||
|
else -- lua 5.2
|
||||||
|
chunk, err = load(code, chunkname, "t", evil_magic)
|
||||||
|
end
|
||||||
if not chunk then
|
if not chunk then
|
||||||
msg.error("Profile '" .. name .. "' condition: " .. err)
|
msg.error("Profile '" .. name .. "' condition: " .. err)
|
||||||
chunk = function() return false end
|
chunk = function() return false end
|
||||||
end
|
end
|
||||||
if setfenv then
|
|
||||||
setfenv(chunk, evil_magic)
|
|
||||||
end
|
|
||||||
return chunk
|
return chunk
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user