summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-18 10:07:53 +0800
committerruki <[email protected]>2021-09-18 10:07:53 +0800
commit1b231d9a73299528f1e336d4038c120d5a4fd183 (patch)
tree7e32b70efaae948c63c4139e3b465f4a07f696d1
parent6f0f25b64487a32989cb718aa50d9bc729f46d66 (diff)
add xmake.luajit
-rw-r--r--core/src/xmake/engine.c8
-rw-r--r--xmake/core/_xmake_main.lua1
-rw-r--r--xmake/core/base/table.lua27
-rw-r--r--xmake/core/base/xmake.lua5
-rw-r--r--xmake/core/sandbox/modules/xmake.lua1
5 files changed, 39 insertions, 3 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 53732e783..69aa1e452 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -892,6 +892,14 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c
lua_pushstring(engine->lua, name? name : "xmake");
lua_setglobal(engine->lua, "_NAME");
+ // use luajit as backend?
+#ifdef USE_LUAJIT
+ lua_pushboolean(engine->lua, tb_true);
+#else
+ lua_pushboolean(engine->lua, tb_false);
+#endif
+ lua_setglobal(engine->lua, "_LUAJIT");
+
// init namespace: xmake
lua_newtable(engine->lua);
lua_setglobal(engine->lua, "xmake");
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index ec1492ca8..af9b51114 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -34,6 +34,7 @@ xmake._PROJECT_DIR = _PROJECT_DIR
xmake._PROJECT_FILE = "xmake.lua"
xmake._WORKING_DIR = os.curdir()
xmake._FEATURES = _FEATURES
+xmake._LUAJIT = _LUAJIT
function _loadfile_impl(filepath, mode, opt)
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 01a6a4692..6709ada3a 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -21,9 +21,30 @@
-- define module: table
local table = table or {}
--- import jit function
-table.clear = require("table.clear")
-table.new = require("table.new")
+-- clear table
+if not table.clear then
+ if xmake._LUAJIT then
+ table.clear = require("table.clear")
+ else
+ function table.clear(t)
+ for k, v in pairs(t) do
+ t[k] = nil
+ end
+ end
+ end
+end
+
+-- new table
+if not table.new then
+ if xmake._LUAJIT then
+ table.new = require("table.new")
+ else
+ function table.new(narray, nhash)
+ -- TODO
+ return {}
+ end
+ end
+end
-- move values of table(a1) to table(a2)
--
diff --git a/xmake/core/base/xmake.lua b/xmake/core/base/xmake.lua
index 406b85b7e..239540a5a 100644
--- a/xmake/core/base/xmake.lua
+++ b/xmake/core/base/xmake.lua
@@ -47,5 +47,10 @@ function xmake.programfile()
return xmake._PROGRAM_FILE
end
+-- use luajit?
+function xmake.luajit()
+ return xmake._LUAJIT
+end
+
-- return module: xmake
return xmake
diff --git a/xmake/core/sandbox/modules/xmake.lua b/xmake/core/sandbox/modules/xmake.lua
index 414258198..fcc6437e1 100644
--- a/xmake/core/sandbox/modules/xmake.lua
+++ b/xmake/core/sandbox/modules/xmake.lua
@@ -28,6 +28,7 @@ local sandbox_xmake = sandbox_xmake or {}
sandbox_xmake.version = xmake.version
sandbox_xmake.programdir = xmake.programdir
sandbox_xmake.programfile = xmake.programfile
+sandbox_xmake.luajit = xmake.luajit
-- return module
return sandbox_xmake