diff options
author | Philip Sequeira <phsequei@gmail.com> | 2020-12-02 01:38:39 -0500 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2020-12-08 17:29:19 +0000 |
commit | df805cfc848ea87ebe489af37946dce8c0a51d7d (patch) | |
tree | 8e4b16c2b2db6985d18bca76d248c2d9c3f0b813 /player | |
parent | 36e569b242a2825b861f8f4bcef9f2ce520bc6d3 (diff) | |
download | mpv-df805cfc848ea87ebe489af37946dce8c0a51d7d.tar.bz2 mpv-df805cfc848ea87ebe489af37946dce8c0a51d7d.tar.xz |
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.
Diffstat (limited to 'player')
-rw-r--r-- | player/lua/auto_profiles.lua | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/player/lua/auto_profiles.lua b/player/lua/auto_profiles.lua index 6856138d97..fba57cc74a 100644 --- a/player/lua/auto_profiles.lua +++ b/player/lua/auto_profiles.lua @@ -136,16 +136,20 @@ setmetatable(p, { }) local function compile_cond(name, s) - -- (pre 5.2 ignores the extra arguments) - local chunk, err = load("return " .. s, "profile " .. name .. " condition", - "t", evil_magic) + local code, chunkname = "return " .. s, "profile " .. name .. " condition" + local chunk, err + 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 msg.error("Profile '" .. name .. "' condition: " .. err) chunk = function() return false end end - if setfenv then - setfenv(chunk, evil_magic) - end return chunk end |