From a9a249217b35ebe5d55474f4035966a7c09b2b1a Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 16 Jul 2020 22:40:33 +0800 Subject: add lua-cjson --- .gitmodules | 3 +++ core/src/lua-cjson/lua-cjson | 1 + 2 files changed, 4 insertions(+) create mode 160000 core/src/lua-cjson/lua-cjson diff --git a/.gitmodules b/.gitmodules index 22ed3f533..ac5f4dde3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "core/src/pdcurses/pdcurses"] path = core/src/pdcurses/pdcurses url = ../../xmake-io/xmake-core-pdcurses.git +[submodule "core/src/lua-cjson/lua-cjson"] + path = core/src/lua-cjson/lua-cjson + url = ../../xmake-io/xmake-core-lua-cjson.git diff --git a/core/src/lua-cjson/lua-cjson b/core/src/lua-cjson/lua-cjson new file mode 160000 index 000000000..e8972ac75 --- /dev/null +++ b/core/src/lua-cjson/lua-cjson @@ -0,0 +1 @@ +Subproject commit e8972ac754788d3ef10a57a36016d6c3e85ba20d -- cgit v1.3.1 From 5f9cbe1960991a7a4d5e577e0a3c4e862c2b5cd1 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 16 Jul 2020 22:41:13 +0800 Subject: add lua-cjson license to NOTICE --- NOTICE.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/NOTICE.md b/NOTICE.md index 62c4c6a21..bedcb05f5 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -5,6 +5,14 @@ This product includes software developed by The TBOOX Open Source Group (https:/ ------------------------------------------------------------------------------- +This product depends on 'lua-cjson', The Lua CJSON module provides JSON support for Lua, +which can be obtained at: + + * LICENSE: + * core/src/lua-cjson/lua-cjson/LICENSE (MIT License) + * HOMEPAGE: + * https://www.kyne.com.au/~mark/software/lua-cjson.php + This product depends on 'pdcurses', an implementation of X/Open curses for multiple platforms, which can be obtained at: @@ -25,7 +33,7 @@ This product depends on 'libsv', Public domain semantic versioning in c, which can be obtained at: * LICENSE: - * core/src/sv/repo/UNLICENSE (Public Domain License) + * core/src/sv/sv/UNLICENSE (Public Domain License) * HOMEPAGE: * https://github.com/uael/sv @@ -33,7 +41,7 @@ This product depends on 'LuaJIT', a Just-In-Time Compiler for Lua, which can be obtained at: * LICENSE: - * core/src/luajit/repo/COPYRIGHT (MIT License) + * core/src/luajit/luajit/COPYRIGHT (MIT License) * HOMEPAGE: * http://luajit.org/ @@ -41,7 +49,7 @@ This product depends on 'tbox', The Treasure Box Library, which can be obtained at: * LICENSE: - * core/src/tbox/repo/LICENSE.md (Apache License 2.0) + * core/src/tbox/tbox/LICENSE.md (Apache License 2.0) * HOMEPAGE: * https://tboox.org/ -- cgit v1.3.1 From f34b7e35cc1c636ae9f3656b3deba0597435a726 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 16 Jul 2020 22:50:41 +0800 Subject: build lua-cjson --- core/src/demo/makefile | 4 ++-- core/src/lua-cjson/lua-cjson | 2 +- core/src/lua-cjson/makefile | 30 ++++++++++++++++++++++++++++++ core/src/lua-cjson/xmake.lua | 15 +++++++++++++++ core/src/makefile | 2 +- core/src/xmake/xmake.lua | 2 +- core/xmake.lua | 2 +- 7 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 core/src/lua-cjson/makefile create mode 100644 core/src/lua-cjson/xmake.lua diff --git a/core/src/demo/makefile b/core/src/demo/makefile index 4ab0e2dba..160174661 100644 --- a/core/src/demo/makefile +++ b/core/src/demo/makefile @@ -14,9 +14,9 @@ demo_C_FILES += xmake demo_PKGS-$(BASE) += base # others -demo_LIBS += xmake$(DTYPE) lcurses$(DTYPE) tbox$(DTYPE) luajit$(DTYPE) sv$(DTYPE) $(BASE_LIBS) +demo_LIBS += xmake$(DTYPE) lcurses$(DTYPE) tbox$(DTYPE) luajit$(DTYPE) sv$(DTYPE) lua-cjson$(DTYPE) $(BASE_LIBS) demo_INC_DIRS += ../ ../tbox/tbox/src ../tbox/inc/$(PLAT) ../luajit/luajit/src ../sv/sv/include -demo_LIB_DIRS += ../xmake ../tbox ../luajit ../sv ../lcurses +demo_LIB_DIRS += ../xmake ../tbox ../luajit ../sv ../lcurses ../lua-cjson demo_CXFLAGS += -D__tb_prefix__=\"xmake\" # suffix diff --git a/core/src/lua-cjson/lua-cjson b/core/src/lua-cjson/lua-cjson index e8972ac75..ab5ec0ea2 160000 --- a/core/src/lua-cjson/lua-cjson +++ b/core/src/lua-cjson/lua-cjson @@ -1 +1 @@ -Subproject commit e8972ac754788d3ef10a57a36016d6c3e85ba20d +Subproject commit ab5ec0ea2de2603bb01e6ea33f7e3197d431ec5a diff --git a/core/src/lua-cjson/makefile b/core/src/lua-cjson/makefile new file mode 100644 index 000000000..0a4263f03 --- /dev/null +++ b/core/src/lua-cjson/makefile @@ -0,0 +1,30 @@ +# prefix +include $(PRO_DIR)/prefix.mak + +# module name +NAMES = lua-cjson + +# module type +lua-cjson_TYPE = LIB + +# config +lua-cjson_CONFIG = n + +# core files +lua-cjson_C_FILES += \ + lua-cjson/dtoa \ + lua-cjson/g_fmt \ + lua-cjson/strbuf \ + lua-cjson/lua_cjson + +# cflags +# Use internal strtod() / g_fmt() code for performance and disable multi-thread +lua-cjson_CFLAGS += -DNDEBUG -DUSE_INTERNAL_FPCONV + +# includes +lua-cjson_INC_DIRS += \ + ../luajit/luajit/src + +# suffix +include $(PRO_DIR)/suffix.mak + diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua new file mode 100644 index 000000000..76caf9fc7 --- /dev/null +++ b/core/src/lua-cjson/xmake.lua @@ -0,0 +1,15 @@ +target("lua-cjson") + set_kind("static") + set_warnings("all") + add_deps("luajit") + if is_plat("windows") then + set_languages("c89") + end + add_files("lua-cjson/*.c|fpconv.c") + -- Use internal strtod() / g_fmt() code for performance and disable multi-thread + add_defines("NDEBUG", "USE_INTERNAL_FPCONV") + if is_plat("windows") then + -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported. + add_defines("DISABLE_INVALID_NUMBERS") + end + diff --git a/core/src/makefile b/core/src/makefile index 5793c13b7..21a06ed5a 100644 --- a/core/src/makefile +++ b/core/src/makefile @@ -3,7 +3,7 @@ include $(PRO_DIR)/prefix.mak # projects SUB_PROS += demo -DEP_PROS += lcurses sv luajit tbox xmake +DEP_PROS += lcurses sv luajit lua-cjson tbox xmake # suffix include $(PRO_DIR)/suffix.mak diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index d85b2802f..eb2cc62b9 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -8,7 +8,7 @@ target("xmake") if has_config("curses") or has_config("pdcurses") then add_deps("lcurses") end - add_deps("sv", "luajit", "tbox") + add_deps("sv", "luajit", "lua-cjson", "tbox") -- add defines add_defines("__tb_prefix__=\"xmake\"") diff --git a/core/xmake.lua b/core/xmake.lua index 2f1f43957..25009801e 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -76,7 +76,7 @@ if is_plat("windows") then end -- add projects -includes("src/lcurses", "src/sv","src/luajit", "src/tbox", "src/xmake", "src/demo") +includes("src/lua-cjson", "src/lcurses", "src/sv","src/luajit", "src/tbox", "src/xmake", "src/demo") if is_plat("windows") then includes("src/pdcurses") end -- cgit v1.3.1 From 764e35f2110e9932dfce409ee3949fccfef521ed Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 00:48:12 +0800 Subject: export cjson as json --- core/src/xmake/engine.c | 7 ++++++ xmake/core/base/json.lua | 29 ++++++++++++++++++++++ .../core/sandbox/modules/import/core/base/json.lua | 24 ++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 xmake/core/base/json.lua create mode 100644 xmake/core/sandbox/modules/import/core/base/json.lua diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index cf361a8c5..337627047 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -224,6 +224,9 @@ tb_int_t xm_semver_select(lua_State* lua); tb_int_t xm_curses_register(lua_State* lua); #endif +// open cjson +tb_int_t luaopen_cjson(lua_State *l); + /* ////////////////////////////////////////////////////////////////////////////////////// * globals */ @@ -849,6 +852,10 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c lua_setglobal(engine->lua, "curses"); #endif + // bind json + luaopen_cjson(engine->lua); + lua_setglobal(engine->lua, "json"); + // init host xm_engine_init_host(engine); diff --git a/xmake/core/base/json.lua b/xmake/core/base/json.lua new file mode 100644 index 000000000..26dbce173 --- /dev/null +++ b/xmake/core/base/json.lua @@ -0,0 +1,29 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file json.lua +-- + +-- define module: json +local json = json or {} + +-- hide some cjson members +json._VERSION = nil +json._NAME = nil + +-- return module: json +return json diff --git a/xmake/core/sandbox/modules/import/core/base/json.lua b/xmake/core/sandbox/modules/import/core/base/json.lua new file mode 100644 index 000000000..c8f428298 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/base/json.lua @@ -0,0 +1,24 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file json.lua +-- + +-- load modules +return require("base/json") + + -- cgit v1.3.1 From 4b39a01e80756cce66f966c9c5f24fcc3e616704 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 00:49:20 +0800 Subject: improve dlist --- xmake/core/base/dlist.lua | 4 ++-- xmake/core/ui/panel.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake/core/base/dlist.lua b/xmake/core/base/dlist.lua index 0657538e7..5d616c6c8 100644 --- a/xmake/core/base/dlist.lua +++ b/xmake/core/base/dlist.lua @@ -206,8 +206,8 @@ function dlist:ritems() end -- new dlist -function dlist:new() - return self() +function dlist.new() + return dlist() end -- return module: dlist diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua index 7cff86eff..c876aa412 100644 --- a/xmake/core/ui/panel.lua +++ b/xmake/core/ui/panel.lua @@ -43,7 +43,7 @@ function panel:init(name, bounds) self:option_set("selectable", true) -- init child views - self._VIEWS = dlist:new() + self._VIEWS = dlist.new() -- init views cache self._VIEWS_CACHE = {} -- cgit v1.3.1 From 3cd22b26a4b0abe9bed7360875718743a7bb5140 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 00:51:12 +0800 Subject: improve release --- core/xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/xmake.lua b/core/xmake.lua index 25009801e..3e3a92acd 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -15,6 +15,9 @@ set_languages("c99", "cxx11") -- add release and debug modes add_rules("mode.release", "mode.debug") +if is_mode("release") then + set_optimize("smallest") +end -- disable some compiler errors add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing", "-Wno-error=nullability-completeness", "-Wno-error=parentheses-equality") -- cgit v1.3.1 From 5131b2b062b478c4ca6dd3310ef139bfe05afc7c Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 00:52:33 +0800 Subject: improve release --- core/xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/xmake.lua b/core/xmake.lua index 3e3a92acd..4ce9c637b 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -17,6 +17,9 @@ set_languages("c99", "cxx11") add_rules("mode.release", "mode.debug") if is_mode("release") then set_optimize("smallest") + if is_plat("windows") then + add_ldflags("/LTCG") + end end -- disable some compiler errors -- cgit v1.3.1 From 5c4e36e63a63742fc81910cce39a2fc54b36db05 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 00:58:45 +0800 Subject: fix compile errors --- core/src/lua-cjson/xmake.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua index 76caf9fc7..9c93fb562 100644 --- a/core/src/lua-cjson/xmake.lua +++ b/core/src/lua-cjson/xmake.lua @@ -2,9 +2,6 @@ target("lua-cjson") set_kind("static") set_warnings("all") add_deps("luajit") - if is_plat("windows") then - set_languages("c89") - end add_files("lua-cjson/*.c|fpconv.c") -- Use internal strtod() / g_fmt() code for performance and disable multi-thread add_defines("NDEBUG", "USE_INTERNAL_FPCONV") -- cgit v1.3.1 From a586eb19b8e24e97cb41918f3e692f6fc7b35368 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 22:33:46 +0800 Subject: fix link errors for msvc --- core/src/lua-cjson/xmake.lua | 3 +++ core/src/xmake/engine.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua index 9c93fb562..76caf9fc7 100644 --- a/core/src/lua-cjson/xmake.lua +++ b/core/src/lua-cjson/xmake.lua @@ -2,6 +2,9 @@ target("lua-cjson") set_kind("static") set_warnings("all") add_deps("luajit") + if is_plat("windows") then + set_languages("c89") + end add_files("lua-cjson/*.c|fpconv.c") -- Use internal strtod() / g_fmt() code for performance and disable multi-thread add_defines("NDEBUG", "USE_INTERNAL_FPCONV") diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 337627047..fb6205ac5 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -225,7 +225,9 @@ tb_int_t xm_curses_register(lua_State* lua); #endif // open cjson +__tb_extern_c_enter__ tb_int_t luaopen_cjson(lua_State *l); +__tb_extern_c_leave__ /* ////////////////////////////////////////////////////////////////////////////////////// * globals -- cgit v1.3.1 From a9f65fda1e6fdf15d8e695308e39859141373503 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 22:35:05 +0800 Subject: fix strncasecmp for cjson --- core/src/lua-cjson/xmake.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua index 76caf9fc7..1d7229aa2 100644 --- a/core/src/lua-cjson/xmake.lua +++ b/core/src/lua-cjson/xmake.lua @@ -11,5 +11,6 @@ target("lua-cjson") if is_plat("windows") then -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported. add_defines("DISABLE_INVALID_NUMBERS") + add_defines("strncasecmp=_strnicmp") end -- cgit v1.3.1 From ebed90e5a6f358e375a8efd0c57c29f4dca59331 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 22:38:41 +0800 Subject: fix compile errors for vs2013 --- core/src/lua-cjson/xmake.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua index 1d7229aa2..cdf3502a9 100644 --- a/core/src/lua-cjson/xmake.lua +++ b/core/src/lua-cjson/xmake.lua @@ -12,5 +12,6 @@ target("lua-cjson") -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported. add_defines("DISABLE_INVALID_NUMBERS") add_defines("strncasecmp=_strnicmp") + add_defines("inline=__inline") end -- cgit v1.3.1 From 6b3cf4e5239f3f041501d0d8ee32471f33010708 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2020 22:41:11 +0800 Subject: update lua-cjson --- core/src/lua-cjson/lua-cjson | 2 +- core/src/lua-cjson/xmake.lua | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/lua-cjson/lua-cjson b/core/src/lua-cjson/lua-cjson index ab5ec0ea2..ddd218d35 160000 --- a/core/src/lua-cjson/lua-cjson +++ b/core/src/lua-cjson/lua-cjson @@ -1 +1 @@ -Subproject commit ab5ec0ea2de2603bb01e6ea33f7e3197d431ec5a +Subproject commit ddd218d35f65a3e0a9f45de5e897f5c319ee4a82 diff --git a/core/src/lua-cjson/xmake.lua b/core/src/lua-cjson/xmake.lua index cdf3502a9..b25640cae 100644 --- a/core/src/lua-cjson/xmake.lua +++ b/core/src/lua-cjson/xmake.lua @@ -11,7 +11,6 @@ target("lua-cjson") if is_plat("windows") then -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported. add_defines("DISABLE_INVALID_NUMBERS") - add_defines("strncasecmp=_strnicmp") add_defines("inline=__inline") end -- cgit v1.3.1