Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jonathan Wilkes
pd-lua
Compare Revisions
4816ca85fd1ed52d97acfd4e5a41b0b5ab11b029...04a966c80962a7c218d1ee37398b17447c0e60e6
Commits (1)
lexpr, ltabfill: Lua 5.3 compatibility
· 04a966c8
Albert Gräf
authored
Mar 23, 2018
04a966c8
Hide whitespace changes
Inline
Side-by-side
examples/lexpr.pd_lua
View file @
04a966c8
...
...
@@ -19,6 +19,10 @@ if not setfenv then -- Lua 5.2
return f end
end
if not loadstring then -- Lua 5.3
loadstring = load
end
local function sandbox(e, f) -- only supports nullary f() with one return
local g = getfenv(f)
setfenv(f, e)
...
...
examples/ltabfill.pd_lua
View file @
04a966c8
local ltabfill = pd.Class:new():register("ltabfill")
-- AG: Lua 5.2 compatibility (cf. https://stackoverflow.com/a/14554565)
if not setfenv then -- Lua 5.2
-- based on http://lua-users.org/lists/lua-l/2010-06/msg00314.html
-- this assumes f is a function
local function findenv(f)
local level = 1
repeat
local name, value = debug.getupvalue(f, level)
if name == '_ENV' then return level, value end
level = level + 1
until name == nil
return nil end
getfenv = function (f) return(select(2, findenv(f)) or _G) end
setfenv = function (f, t)
local level = findenv(f)
if level then debug.setupvalue(f, level, t) end
return f end
end
if not loadstring then -- Lua 5.3
loadstring = load
end
local function sandbox(e, f, x) -- only supports unary f() with one return
local g = getfenv(f)
setfenv(f, e)
...
...