Skip to content

Commit

Permalink
Reverted to requiring Lua 5.2
Browse files Browse the repository at this point in the history
Can't deal with 5.1 right now....
  • Loading branch information
vercas committed Mar 30, 2017
1 parent d1bfcb0 commit 6e8d663
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
6 changes: 3 additions & 3 deletions vmake-2.0.0-18.rockspec → vmake-2.0.1-19.rockspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package = "vmake"
version = "2.0.0-18"
version = "2.0.1-19"

source = {
url = "git://github.com/vercas/vMake",
tag = "v2.0.0-5.1",
tag = "v2.0.1",
}

description = {
Expand All @@ -13,7 +13,7 @@ description = {
}

dependencies = {
"lua >= 5.1",
"lua >= 5.2",
}

build = {
Expand Down
61 changes: 60 additions & 1 deletion vmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,66 @@ do
end

if setfenv then
error("TODO")
local cache = {}

function withEnvironment(f, env)
if cache[f] and cache[f][env] then
return cache[f][env]
end

local bytecode = string.dump(f)

-- TODO: Get function info.

local new, err = loadstring(bytecode)

if not new then
error("vMake internal error: Failed to copy function " .. "<TODO>" .. " to change its environment: " .. err, 1)
end

setfenv(new, env)

local i, nameN = 1

repeat
nameN = debug.getupvalue(new, i)

if not nameN then
break
end

local j, nameO, temp = 1

repeat
nameO, temp = debug.getupvalue(f, j)

if nameO == nameN then
debug.setupvalue(new, i, temp)

break
end

j = j + 1
until not nameO

if not nameO then
error("vMake internal error: Failed to set upvalue \"" .. nameN .. "\" of function " .. "<TODO>", 1)
end

i = i + 1
until not nameN

if cache[f] then
cache[f][env] = new
else
cache[f] = { [env] = new }
end

cache[new] = { [env] = new }
-- Yup, cache this one as well.

return new
end
else
local cache = {}

Expand Down

0 comments on commit 6e8d663

Please sign in to comment.