From df805cfc848ea87ebe489af37946dce8c0a51d7d Mon Sep 17 00:00:00 2001 From: Philip Sequeira Date: Wed, 2 Dec 2020 01:38:39 -0500 Subject: 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. --- player/lua/auto_profiles.lua | 16 ++++++++++------ 1 file 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 -- cgit v1.2.3