summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/core/_xmake_main.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index af9b51114..94045a2f5 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -36,6 +36,42 @@ xmake._WORKING_DIR = os.curdir()
xmake._FEATURES = _FEATURES
xmake._LUAJIT = _LUAJIT
+-- init setfenv/getfenv for lua
+if not getfenv then
+ function getfenv(fn)
+ local i = 1
+ while true do
+ local name, val = debug.getupvalue(fn, i)
+ if name == "_ENV" then
+ return val
+ elseif not name then
+ break
+ end
+ i = i + 1
+ end
+ end
+end
+if not setfenv then
+ function setfenv(fn, env)
+ local i = 1
+ while true do
+ local name = debug.getupvalue(fn, i)
+ if name == "_ENV" then
+ debug.upvaluejoin(fn, i, (function()
+ return env
+ end), 1)
+ break
+ elseif not name then
+ break
+ end
+
+ i = i + 1
+ end
+ return fn
+ end
+end
+
+-- load the given lua file
function _loadfile_impl(filepath, mode, opt)
-- init options