diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/makefile | 5 | ||||
| -rw-r--r-- | core/project.mak | 2 | ||||
| -rw-r--r-- | core/src/demo/makefile | 10 | ||||
| -rw-r--r-- | core/src/lcurses/lcurses.c | 10 | ||||
| -rw-r--r-- | core/src/lcurses/makefile | 9 | ||||
| -rw-r--r-- | core/src/lcurses/xmake.lua | 2 | ||||
| -rw-r--r-- | core/src/lua-cjson/makefile | 10 | ||||
| -rw-r--r-- | core/src/lua-cjson/xmake.lua | 2 | ||||
| m--------- | core/src/lua/lua | 0 | ||||
| -rw-r--r-- | core/src/lua/makefile | 85 | ||||
| -rw-r--r-- | core/src/lua/xmake.lua | 31 | ||||
| -rw-r--r-- | core/src/luajit/xmake.lua | 5 | ||||
| -rw-r--r-- | core/src/makefile | 10 | ||||
| -rw-r--r-- | core/src/xmake/engine.c | 10 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 9 | ||||
| -rw-r--r-- | core/src/xmake/prefix.h | 12 | ||||
| -rw-r--r-- | core/src/xmake/sandbox/interactive.c | 4 | ||||
| -rw-r--r-- | core/src/xmake/xmake.lua | 3 | ||||
| -rw-r--r-- | core/xmake.lua | 10 |
19 files changed, 214 insertions, 15 deletions
diff --git a/core/makefile b/core/makefile index 0bba754cd..d7c529489 100644 --- a/core/makefile +++ b/core/makefile @@ -368,6 +368,7 @@ config : .null @$(ECHO) "directories:" @$(ECHO) " install:\t\t"$(abspath $(INSTALL)) @$(ECHO) " package:\t\t"$(PACKAGE) + @$(ECHO) " backend:\t\t"$(BACKEND) @$(ECHO) "" @$(ECHO) "toolchains:" @$(ECHO) " bin:\t\t"$(BIN) @@ -459,6 +460,10 @@ config : .null @$(ECHO) "export MIPS" >> .config.mak @$(ECHO) "export SPARC" >> .config.mak @$(ECHO) "" >> .config.mak + @$(ECHO) "# backend" >> .config.mak + @$(ECHO) "BACKEND ="$(BACKEND) >> .config.mak + @$(ECHO) "export BACKEND" >> .config.mak + @$(ECHO) "" >> .config.mak @$(ECHO) "# demo" >> .config.mak @$(ECHO) "DEMO ="$(DEMO) >> .config.mak @$(ECHO) "export DEMO" >> .config.mak diff --git a/core/project.mak b/core/project.mak index 041121fea..adf613ef2 100644 --- a/core/project.mak +++ b/core/project.mak @@ -16,5 +16,5 @@ PRO_VERSION_ALTER = 7 PRO_PREFIX = XM_ # the package names -PKG_NAMES = tbox luajit base +PKG_NAMES = tbox luajit lua base diff --git a/core/src/demo/makefile b/core/src/demo/makefile index 1a2142db5..93525ddaf 100644 --- a/core/src/demo/makefile +++ b/core/src/demo/makefile @@ -20,10 +20,20 @@ demo_INC_DIRS += ../ ../tbox/tbox/src ../tbox/inc/$(PLAT) demo_LIB_DIRS += ../tbox # luajit +ifeq ($(BACKEND),luajit) luajit_LIBS := $(if $(findstring luajit,$(base_LIBNAMES)),,luajit$(DTYPE)) demo_LIBS += $(luajit_LIBS) demo_INC_DIRS += ../luajit/luajit/src demo_LIB_DIRS += ../luajit +endif + +# lua +ifeq ($(BACKEND),lua) +lua_LIBS := $(if $(findstring lua,$(base_LIBNAMES)),,lua$(DTYPE)) +demo_LIBS += $(lua_LIBS) +demo_INC_DIRS += ../lua/lua +demo_LIB_DIRS += ../lua +endif # sv sv_DTYPE := $(if $(findstring sv,$(base_LIBNAMES)),,$(DTYPE)) diff --git a/core/src/lcurses/lcurses.c b/core/src/lcurses/lcurses.c index 934dc2d1d..f3bdf7244 100644 --- a/core/src/lcurses/lcurses.c +++ b/core/src/lcurses/lcurses.c @@ -65,9 +65,15 @@ Notes: #include <stdlib.h> #include <string.h> +#ifdef USE_LUAJIT #include "luajit.h" #include "lualib.h" #include "lauxlib.h" +#else +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +#endif #include <curses.h> #include <signal.h> @@ -330,7 +336,11 @@ static chtype lc_checkch(lua_State *L, int index) if (lua_type(L, index) == LUA_TSTRING) return *lua_tostring(L, index); +#ifdef USE_LUAJIT luaL_typerror(L, index, "chtype"); +#else + // TODO +#endif /* never executes */ return (chtype)0; } diff --git a/core/src/lcurses/makefile b/core/src/lcurses/makefile index 25752ab47..a0d6a6400 100644 --- a/core/src/lcurses/makefile +++ b/core/src/lcurses/makefile @@ -17,7 +17,14 @@ lcurses_C_FILES += lcurses lcurses_CXFLAGS += $(if $(findstring curses,$(base_LIBNAMES)),-DXM_CONFIG_API_HAVE_CURSES,) # includes -lcurses_INC_DIRS += ../luajit/luajit/src +ifeq ($(BACKEND),luajit) +lcurses_INC_DIRS += ../luajit/luajit/src +lcurses_CXFLAGS += -DUSE_LUAJIT +endif +ifeq ($(BACKEND),lua) +lcurses_INC_DIRS += ../lua/lua +lcurses_CXFLAGS += -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 +endif # suffix include $(PRO_DIR)/suffix.mak diff --git a/core/src/lcurses/xmake.lua b/core/src/lcurses/xmake.lua index f80117f10..5ee8a26c6 100644 --- a/core/src/lcurses/xmake.lua +++ b/core/src/lcurses/xmake.lua @@ -1,6 +1,6 @@ target("lcurses") set_kind("static") - add_deps("luajit") + add_deps(get_config("backend")) if is_plat("windows") and has_config("pdcurses") then add_deps("pdcurses") add_defines("XM_CONFIG_API_HAVE_CURSES", {public = true}) diff --git a/core/src/lua-cjson/makefile b/core/src/lua-cjson/makefile index 9e96851ae..e1d53ecf9 100644 --- a/core/src/lua-cjson/makefile +++ b/core/src/lua-cjson/makefile @@ -22,8 +22,14 @@ lua-cjson_C_FILES += \ lua-cjson_CFLAGS += -DNDEBUG -DUSE_INTERNAL_FPCONV # includes -lua-cjson_INC_DIRS += \ - ../luajit/luajit/src +ifeq ($(BACKEND),luajit) +lua-cjson_INC_DIRS += ../luajit/luajit/src +lua-cjson_CXFLAGS += -DUSE_LUAJIT +endif +ifeq ($(BACKEND),lua) +lua-cjson_INC_DIRS += ../lua/lua +lua-cjson_CXFLAGS += -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 +endif # use given system library? lua-cjson_C_FILES := $(if $(findstring cjson,$(base_LIBNAMES)),,$(lua-cjson_C_FILES)) diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua index d2eec99f0..d3b12ded1 100644 --- a/core/src/lua-cjson/xmake.lua +++ b/core/src/lua-cjson/xmake.lua @@ -1,7 +1,7 @@ target("lua-cjson") set_kind("static") set_warnings("all") - add_deps("luajit") + add_deps(get_config("backend")) if is_plat("windows") then set_languages("c89") end diff --git a/core/src/lua/lua b/core/src/lua/lua new file mode 160000 +Subproject 75ea9ccbea7c4886f30da147fb67b693b2624c2 diff --git a/core/src/lua/makefile b/core/src/lua/makefile new file mode 100644 index 000000000..4137fd22c --- /dev/null +++ b/core/src/lua/makefile @@ -0,0 +1,85 @@ +# prefix +include $(PRO_DIR)/prefix.mak + +# module name +NAMES = lua + +# module type +lua_TYPE = LIB + +# config +lua_CONFIG = n + +# core files +lua_C_FILES += \ + lua/lauxlib \ + lua/liolib \ + lua/lopcodes \ + lua/lstate \ + lua/lobject \ + lua/lmathlib \ + lua/loadlib \ + lua/lvm \ + lua/lfunc \ + lua/lstrlib \ + lua/linit \ + lua/lstring \ + lua/lundump \ + lua/lctype \ + lua/ltable \ + lua/ldump \ + lua/loslib \ + lua/lgc \ + lua/lzio \ + lua/ldblib \ + lua/lutf8lib \ + lua/lmem \ + lua/lcorolib \ + lua/lcode \ + lua/ltablib \ + lua/lbitlib \ + lua/lapi \ + lua/lbaselib \ + lua/ldebug \ + lua/lparser \ + lua/llex \ + lua/ltm \ + lua/ltests \ + lua/ldo + +# is windows? +iswin = +ifeq ($(PLAT),windows) + iswin = yes +endif +ifeq ($(PLAT),msys) + iswin = yes +endif +ifeq ($(PLAT),mingw) + iswin = yes +endif +ifeq ($(PLAT),cygwin) + iswin = yes +endif + +lua_CFLAGS := -std=c99 -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 +ifdef iswin +lua_CFLAGS += -DLUA_USE_WINDOWS +endif + +ifeq ($(PLAT),macosx) +lua_CFLAGS += -DLUA_USE_MACOSX \ + -Wno-error=string-plus-int +else +lua_CFLAGS += -DLUA_USE_LINUX +endif + +# use given system library? +lua_C_FILES := $(if $(findstring lua,$(base_LIBNAMES)),,$(lua_C_FILES)) +lua_ASM_FILES := $(if $(findstring lua,$(base_LIBNAMES)),,$(lua_ASM_FILES)) +lua_INC_FILES := $(if $(findstring lua,$(base_LIBNAMES)),,$(lua_INC_FILES)) +lua_OBJ_FILES := $(if $(findstring lua,$(base_LIBNAMES)),,$(lua_OBJ_FILES)) + +# suffix +include $(PRO_DIR)/suffix.mak + diff --git a/core/src/lua/xmake.lua b/core/src/lua/xmake.lua new file mode 100644 index 000000000..4f209b693 --- /dev/null +++ b/core/src/lua/xmake.lua @@ -0,0 +1,31 @@ +target("lua") + if not is_config("lua") then + set_default(false) + end + set_kind("static") + set_warnings("all") + + -- disable c99(/TP) for windows + if is_plat("windows") then + set_languages("c89") + end + + -- add header files + add_headerfiles("lua/(*.h)", {prefixdir = "lua"}) + + -- add include directories + add_includedirs("lua", {public = true}) + + -- add the common source files + add_files("lua/*.c|lua.c") + + -- add defines + add_defines("LUA_COMPAT_5_1", "LUA_COMPAT_5_2", {public = true}) + if is_plat("windows") then + add_defines("LUA_USE_WINDOWS") + elseif is_plat("macosx", "iphoneos") then + add_defines("LUA_USE_MACOSX") + else + add_defines("LUA_USE_LINUX") + end + diff --git a/core/src/luajit/xmake.lua b/core/src/luajit/xmake.lua index cfee1f76e..f6f351394 100644 --- a/core/src/luajit/xmake.lua +++ b/core/src/luajit/xmake.lua @@ -23,6 +23,9 @@ local autogendir = path.join("autogen", plat, jit and "jit" or "nojit", arch) -- add target target("luajit") + if not is_config("luajit") then + set_default(false) + end -- make as a static library set_kind("static") @@ -52,6 +55,8 @@ target("luajit") add_files(autogendir .. "/*.S") end + add_defines("USE_LUAJIT", {interface = true}) + -- disable jit compiler? if not jit then add_defines("LUAJIT_DISABLE_JIT") diff --git a/core/src/makefile b/core/src/makefile index 21a06ed5a..47151258e 100644 --- a/core/src/makefile +++ b/core/src/makefile @@ -2,8 +2,14 @@ include $(PRO_DIR)/prefix.mak # projects -SUB_PROS += demo -DEP_PROS += lcurses sv luajit lua-cjson tbox xmake +SUB_PROS += demo +ifeq ($(BACKEND),luajit) +DEP_PROS += luajit +endif +ifeq ($(BACKEND),lua) +DEP_PROS += lua +endif +DEP_PROS += lcurses sv lua-cjson tbox xmake # suffix include $(PRO_DIR)/suffix.mak diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 6a401a486..69aa1e452 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -814,7 +814,7 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c tb_strlcpy(engine->name, name, sizeof(engine->name)); // init lua - engine->lua = lua_open(); + engine->lua = luaL_newstate(); tb_assert_and_check_break(engine->lua); // open lua libraries @@ -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/core/src/xmake/makefile b/core/src/xmake/makefile index 2c45588b4..20bc49d82 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -149,8 +149,15 @@ xmake_CXFLAGS += $(if $(findstring curses,$(base_LIBNAMES)),-DXM_CONFIG xmake_INC_DIRS += \ ../tbox/tbox/src \ ../tbox/inc/$(PLAT) \ - ../luajit/luajit/src \ ../sv/sv/include +ifeq ($(BACKEND),luajit) +xmake_INC_DIRS += ../luajit/luajit/src +xmake_CXFLAGS += -DUSE_LUAJIT +endif +ifeq ($(BACKEND),lua) +xmake_INC_DIRS += ../lua/lua +xmake_CXFLAGS += -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 +endif # suffix diff --git a/core/src/xmake/prefix.h b/core/src/xmake/prefix.h index f1287b5c9..f78b61127 100644 --- a/core/src/xmake/prefix.h +++ b/core/src/xmake/prefix.h @@ -32,9 +32,15 @@ # define LUA_API extern "C" # define LUALIB_API LUA_API #endif -#include "luajit.h" -#include "lualib.h" -#include "lauxlib.h" +#ifdef USE_LUAJIT +# include "luajit.h" +# include "lualib.h" +# include "lauxlib.h" +#else +# include "lua.h" +# include "lualib.h" +# include "lauxlib.h" +#endif /* ////////////////////////////////////////////////////////////////////////////////////// * private interfaces diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index 2519a58e8..023759448 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -73,6 +73,7 @@ static tb_void_t xm_sandbox_report(lua_State *lua) } } +#ifdef USE_LUAJIT // the traceback function static tb_int_t xm_sandbox_traceback(lua_State *lua) { @@ -122,6 +123,7 @@ static tb_int_t xm_sandbox_docall(lua_State* lua, tb_int_t narg, tb_int_t clear) // ok? return status; } +#endif // this line is incomplete? static tb_int_t xm_sandbox_incomplete(lua_State *lua, tb_int_t status) @@ -314,6 +316,7 @@ tb_int_t xm_sandbox_interactive(lua_State* lua) // execute codes if (status == 0) { +#ifdef USE_LUAJIT /* bind sandbox * * stack: arg1(top) scriptfunc arg1(sandbox_scope) -> ... @@ -326,6 +329,7 @@ tb_int_t xm_sandbox_interactive(lua_State* lua) * stack: arg1(top) scriptfunc -> ... */ status = xm_sandbox_docall(lua, 0, 0); +#endif } // report errors diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index 7a604301a..c954db65b 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -7,7 +7,8 @@ target("xmake") if has_config("curses") or has_config("pdcurses") then add_deps("lcurses") end - add_deps("sv", "luajit", "lua-cjson", "tbox") + add_deps("sv", "lua-cjson", "tbox") + add_deps(get_config("backend")) -- add defines add_defines("__tb_prefix__=\"xmake\"") diff --git a/core/xmake.lua b/core/xmake.lua index 9caedf7a9..592bc7c95 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -40,6 +40,14 @@ if is_mode("coverage") then add_ldflags("-coverage", "-fprofile-arcs", "-ftest-coverage") end +-- the backend option +option("backend") + set_showmenu(true) + set_default("luajit") + set_description("Use luajit or lua backend") + set_values("luajit", "lua") +option_end() + -- the readline option option("readline") set_showmenu(true) @@ -80,7 +88,7 @@ if is_plat("windows") then end -- add projects -includes("src/lua-cjson", "src/lcurses", "src/sv","src/luajit", "src/tbox", "src/xmake", "src/demo") +includes("src/lua-cjson", "src/lcurses", "src/sv","src/luajit", "src/lua", "src/tbox", "src/xmake", "src/demo") if is_plat("windows") then includes("src/pdcurses") end |
