diff options
| author | ruki <[email protected]> | 2015-06-09 21:26:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-09 21:26:04 +0800 |
| commit | d61169b7ea72b22ca89d5a6575865af9148d958e (patch) | |
| tree | 47d83d2cc74e1762a01b837686d16f2dc41a78d4 /xmake/scripts | |
| parent | e18c9d7a5718c80852fab0eb89161b4da28b7a94 (diff) | |
list action menu automaticlly
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_clean.lua | 34 | ||||
| -rw-r--r-- | xmake/scripts/action/_config.lua | 115 | ||||
| -rw-r--r-- | xmake/scripts/action/_create.lua | 50 | ||||
| -rw-r--r-- | xmake/scripts/action/_global.lua | 33 | ||||
| -rw-r--r-- | xmake/scripts/action/_install.lua | 35 | ||||
| -rw-r--r-- | xmake/scripts/action/_lua.lua | 34 | ||||
| -rw-r--r-- | xmake/scripts/action/_run.lua | 39 | ||||
| -rw-r--r-- | xmake/scripts/action/action.lua | 54 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 323 | ||||
| -rw-r--r-- | xmake/scripts/base/option.lua | 22 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 1 | ||||
| -rw-r--r-- | xmake/scripts/base/table.lua | 28 |
12 files changed, 447 insertions, 321 deletions
diff --git a/xmake/scripts/action/_clean.lua b/xmake/scripts/action/_clean.lua index 5af3604b7..2a479157f 100644 --- a/xmake/scripts/action/_clean.lua +++ b/xmake/scripts/action/_clean.lua @@ -26,6 +26,7 @@ local _clean = _clean or {} -- load modules local clean = require("base/clean") local config = require("base/config") +local platform = require("platform/platform") -- done the given config function _clean.done() @@ -46,5 +47,38 @@ function _clean.done() return true end +-- the menu +function _clean.menu() + + return { + -- xmake c + shortname = 'c' + + -- usage + , usage = "xmake clean|c [options] [target]" + + -- description + , description = "Remove all binary and temporary files." + + -- options + , options = + { + {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {'P', "project", "kv", nil, "Change to the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "target", "v", "all", "Clean for the given target." } + } + } +end + -- return module: _clean return _clean diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua index 2c1046ecf..9ef333abe 100644 --- a/xmake/scripts/action/_config.lua +++ b/xmake/scripts/action/_config.lua @@ -28,6 +28,7 @@ local utils = require("base/utils") local config = require("base/config") local project = require("base/project") local makefile = require("base/makefile") +local platform = require("platform/platform") -- done the given config function _config.done() @@ -65,5 +66,119 @@ function _config.done() return true end +-- the menu +function _config.menu() + + return { + -- xmake f + shortname = 'f' + + -- usage + , usage = "xmake config|f [options] [target]" + + -- description + , description = "Configure the project." + + -- options + , options = + { + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + + , {} + , {'p', "plat", "kv", xmake._HOST, "Compile for the given platform." + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat + end + end + return descriptions + end } + , {'a', "arch", "kv", "auto", "Compile for the given architecture." + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat .. ":" + local archs = platform.archs(plat) + if archs then + for _, arch in ipairs(archs) do + descriptions[i] = descriptions[i] .. " " .. arch + end + end + end + end + return descriptions + end } + , {'m', "mode", "kv", "release", "Compile for the given mode." + , " - debug" + , " - release" + , " - profile" } + , {'-', "host", "kv", xmake._HOST, "The current host environment." } + + , {} + , {'o', "buildir", "kv", "build", "Set the build directory." } + , {'k', "packages", "kv", "pkg", "Set the packages directory." } + + , {} + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." + , " --ccache=[y|n]" } + + , {} + , {nil, "cross", "kv", nil, "The cross toolchains prefix" + , ".e.g" + , " - i386-mingw32-" + , " - arm-linux-androideabi-" } + , {nil, "toolchains", "kv", nil, "The cross toolchains directory" } + + , {} + , {nil, "cc", "kv", nil, "The C Compiler" } + , {nil, "cxx", "kv", nil, "The C++ Compiler" } + , {nil, "cflags", "kv", nil, "The C Compiler Flags" } + , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } + , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } + + , {} + , {nil, "as", "kv", nil, "The Assembler" } + , {nil, "asflags", "kv", nil, "The Assembler Flags" } + + , {} + , {nil, "ld", "kv", nil, "The Linker" } + , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } + + , {} + , {nil, "ar", "kv", nil, "The Static Library Linker" } + , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } + + , {} + , {nil, "sh", "kv", nil, "The Shared Library Linker" } + , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } + + -- the options for all platforms + , function () return platform.menu("config") end + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {'P', "project", "kv", nil, "Change to the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "target", "v", "all", "Configure for the given target." } + } + } +end + -- return module: _config return _config diff --git a/xmake/scripts/action/_create.lua b/xmake/scripts/action/_create.lua index f60666d71..59aac8a55 100644 --- a/xmake/scripts/action/_create.lua +++ b/xmake/scripts/action/_create.lua @@ -26,6 +26,7 @@ local _create = _create or {} -- load modules local utils = require("base/utils") local config = require("base/config") +local platform = require("platform/platform") -- done the given config function _create.done() @@ -35,5 +36,54 @@ function _create.done() return true end +-- the menu +function _create.menu() + + return { + -- xmake p + shortname = 'p' + + -- usage + , usage = "xmake create|p [options] [target]" + + -- description + , description = "Create a new project." + + -- options + , options = + { + {'n', "name", "kv", nil, "The project name." } + , {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } + , {'P', "project", "kv", nil, "Create from the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + , {'l', "language", "kv", "c", "The project language" + , " - c" + , " - c++" + , " - objc" + , " - objc++" + , " - lua" } + , {'t', "type", "kv", "console", "The project type" + , " - console" + , " - library_static" + , " - library_shared" + , " - application_empty" + , " - application_singleview" + , " - game" } + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "target", "v", nil, "Create the given target" + , "Uses the project name as target if not exists." } + } + } +end + -- return module: _create return _create diff --git a/xmake/scripts/action/_global.lua b/xmake/scripts/action/_global.lua index 5cfaf1bbd..329502c7d 100644 --- a/xmake/scripts/action/_global.lua +++ b/xmake/scripts/action/_global.lua @@ -26,6 +26,7 @@ local _global = _global or {} -- load modules local utils = require("base/utils") local global = require("base/global") +local platform = require("platform/platform") -- done the given config function _global.done() @@ -45,5 +46,37 @@ function _global.done() return true end +-- the menu +function _global.menu() + + return { + -- xmake g + shortname = 'g' + + -- usage + , usage = "xmake global|g [options] [target]" + + -- description + , description = "Configure the global options for xmake." + + -- options + , options = + { + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." + , " --ccache=[y|n]" } + + , {} + -- the options for all platforms + , function () return platform.menu("global") end + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + } + } +end + -- return module: _global return _global diff --git a/xmake/scripts/action/_install.lua b/xmake/scripts/action/_install.lua index 5f5bfac9b..af7edc104 100644 --- a/xmake/scripts/action/_install.lua +++ b/xmake/scripts/action/_install.lua @@ -26,6 +26,7 @@ local _install = _install or {} -- load modules local utils = require("base/utils") local config = require("base/config") +local platform = require("platform/platform") -- done the given config function _install.done() @@ -35,5 +36,39 @@ function _install.done() return true end +-- the menu +function _install.menu() + + return { + -- xmake i + shortname = 'i' + + -- usage + , usage = "xmake install|i [options] [target]" + + -- description + , description = "Package and install the project binary files." + + -- options + , options = + { + {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {'P', "project", "kv", nil, "Change to the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "target", "v", "all", "Install the given target." } + } + } +end + -- return module: _install return _install diff --git a/xmake/scripts/action/_lua.lua b/xmake/scripts/action/_lua.lua index 380c3438b..8801307d2 100644 --- a/xmake/scripts/action/_lua.lua +++ b/xmake/scripts/action/_lua.lua @@ -30,6 +30,7 @@ local utils = require("base/utils") local config = require("base/config") local string = require("base/string") local tools = require("tools/tools") +local platform = require("platform/platform") -- done the given config function _lua.done() @@ -100,5 +101,38 @@ function _lua.done() return false end +-- the menu +function _lua.menu() + + return { + -- xmake l + shortname = 'l' + + -- usage + , usage = "xmake lua|l [options] [script] [arguments]" + + -- description + , description = "Run the lua script." + + -- options + , options = + { + {'s', "string", "k", nil, "Run the lua string script." } + + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "script", "v", nil, "Run the given lua script." + , " - The script name from the xmake tool directory" + , " - The script file" + , " - The script string" } + , {nil, "arguments", "vs", nil, "The script arguments" } + } + } +end + -- return module: _lua return _lua diff --git a/xmake/scripts/action/_run.lua b/xmake/scripts/action/_run.lua index 8de5ab5f1..c2b46ad9b 100644 --- a/xmake/scripts/action/_run.lua +++ b/xmake/scripts/action/_run.lua @@ -29,6 +29,7 @@ local path = require("base/path") local utils = require("base/utils") local config = require("base/config") local project = require("base/project") +local platform = require("platform/platform") -- done the given config function _run.done() @@ -87,5 +88,43 @@ function _run.done() return utils.ifelse(ok == 0, true, false) end +-- the menu +function _run.menu() + + return { + -- xmake r + shortname = 'r' + + -- usage + , usage = "xmake run|r [options] [target] [arguments]" + + -- description + , description = "Run the project target." + + -- options + , options = + { + {'d', "debug", "k", nil, "Run and debug the given target." } + , {nil, "debugger", "kv", "auto", "Set the debugger path." } + + , {} + , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } + , {'P', "project", "kv", nil, "Change to the given project directory." + , "Search priority:" + , " 1. The Given Command Argument" + , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" + , " 3. The Current Directory" } + , {} + , {'v', "verbose", "k", nil, "Print lots of verbose information." } + , {nil, "version", "k", nil, "Print the version number and exit." } + , {'h', "help", "k", nil, "Print this help message and exit." } + + , {} + , {nil, "target", "v", nil, "Run the given target." } + , {nil, "arguments", "vs", nil, "The target arguments" } + } + } +end + -- return module: _run return _run diff --git a/xmake/scripts/action/action.lua b/xmake/scripts/action/action.lua index eab768364..a0574ec58 100644 --- a/xmake/scripts/action/action.lua +++ b/xmake/scripts/action/action.lua @@ -23,16 +23,68 @@ -- define module: action local action = action or {} +-- load modules +local os = require("base/os") +local path = require("base/path") + +-- load the given action +function action._load(name) + + -- load the given action + return require("action/_" .. name) +end + -- done the given action function action.done(name) -- load the given action - local a = require("action/_" .. name) + local a = action._load(name) if not a then return false end -- done the given action return a.done() end +-- list the all actions +function action.list() + + -- find all action scripts + local list = {} + local files = os.match(xmake._SCRIPTS_DIR .. "/action/_*.lua") + if files then + for _, file in ipairs(files) do + local name = path.basename(file) + if name and name ~= "_build" then + table.insert(list, name:sub(2)) + end + end + end + + -- ok? + return list +end + +-- get the all action menus +function action.menu() + + -- get all actions + local menus = {} + local actions = action.list() + for _, name in ipairs(actions) do + + -- load action + local a = action._load(name) + if a and a.menu then + local m = a.menu() + if m then + menus[name] = m + end + end + end + + -- ok? + return menus +end + -- return module: action return action diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index d4945fc6a..8f61b6940 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -52,8 +52,8 @@ local menu = -- description , description = "Build the project if no given action." - , -- actions - actions = {"create", "config", "global", "install", "clean", "run", "lua"} + -- actions + , actions = action.list -- options , options = @@ -81,324 +81,9 @@ local menu = } } - -- create project: xmake create -, create = - { - -- xmake p - shortname = 'p' - - -- usage - , usage = "xmake create|p [options] [target]" - - -- description - , description = "Create a new project." - - -- options - , options = - { - {'n', "name", "kv", nil, "The project name." } - , {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } - , {'P', "project", "kv", nil, "Create from the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" } - , {'l', "language", "kv", "c", "The project language" - , " - c" - , " - c++" - , " - objc" - , " - objc++" - , " - lua" } - , {'t', "type", "kv", "console", "The project type" - , " - console" - , " - library_static" - , " - library_shared" - , " - application_empty" - , " - application_singleview" - , " - game" } - - , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } - - , {} - , {nil, "target", "v", nil, "Create the given target" - , "Uses the project name as target if not exists." } - } - } - - -- config project: xmake config -, config = - { - -- xmake f - shortname = 'f' - - -- usage - , usage = "xmake config|f [options] [target]" - - -- description - , description = "Configure the project." - - -- options - , options = - { - {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } - - , {} - , {'p', "plat", "kv", xmake._HOST, "Compile for the given platform." - , function () - local descriptions = {} - local plats = platform.plats() - if plats then - for i, plat in ipairs(plats) do - descriptions[i] = " - " .. plat - end - end - return descriptions - end } - , {'a', "arch", "kv", "auto", "Compile for the given architecture." - , function () - local descriptions = {} - local plats = platform.plats() - if plats then - for i, plat in ipairs(plats) do - descriptions[i] = " - " .. plat .. ":" - local archs = platform.archs(plat) - if archs then - for _, arch in ipairs(archs) do - descriptions[i] = descriptions[i] .. " " .. arch - end - end - end - end - return descriptions - end } - , {'m', "mode", "kv", "release", "Compile for the given mode." - , " - debug" - , " - release" - , " - profile" } - , {'-', "host", "kv", xmake._HOST, "The current host environment." } - - , {} - , {'o', "buildir", "kv", "build", "Set the build directory." } - , {'k', "packages", "kv", "pkg", "Set the packages directory." } - - , {} - , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." - , " --ccache=[y|n]" } - - , {} - , {nil, "cross", "kv", nil, "The cross toolchains prefix" - , ".e.g" - , " - i386-mingw32-" - , " - arm-linux-androideabi-" } - , {nil, "toolchains", "kv", nil, "The cross toolchains directory" } - - , {} - , {nil, "cc", "kv", nil, "The C Compiler" } - , {nil, "cxx", "kv", nil, "The C++ Compiler" } - , {nil, "cflags", "kv", nil, "The C Compiler Flags" } - , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } - , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } - - , {} - , {nil, "as", "kv", nil, "The Assembler" } - , {nil, "asflags", "kv", nil, "The Assembler Flags" } - - , {} - , {nil, "ld", "kv", nil, "The Linker" } - , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } - - , {} - , {nil, "ar", "kv", nil, "The Static Library Linker" } - , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } - - , {} - , {nil, "sh", "kv", nil, "The Shared Library Linker" } - , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } - - -- the options for all platforms - , function () return platform.menu("config") end - - , {} - , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } - , {'P', "project", "kv", nil, "Change to the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" } - - - , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } - - , {} - , {nil, "target", "v", "all", "Configure for the given target." } - } - } - - -- config global: xmake global -, global = - { - -- xmake g - shortname = 'g' - - -- usage - , usage = "xmake global|g [options] [target]" - - -- description - , description = "Configure the global options for xmake." - - -- options - , options = - { - {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } - , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." - , " --ccache=[y|n]" } - - , {} - -- the options for all platforms - , function () return platform.menu("global") end - - , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } - } - } - - -- install project: xmake install -, install = - { - -- xmake i - shortname = 'i' + -- the actions: xmake [action] +, action.menu - -- usage - , usage = "xmake install|i [options] [target]" - - -- description - , description = "Package and install the project binary files." - - -- options - , options = - { - {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } - , {'P', "project", "kv", nil, "Change to the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" } - - , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } - - , {} - , {nil, "target", "v", "all", "Install the given target." } - } - } - - -- clean project: xmake clean -, clean = - { - -- xmake c - shortname = 'c' - - -- usage - , usage = "xmake clean|c [options] [target]" - - -- description - , description = "Remove all binary and temporary files." - - -- options - , options = - { - {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } - , {'P', "project", "kv", nil, "Change to the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" } - , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } - - , {} - , {nil, "target", "v", "all", "Clean for the given target." } - } - } - - -- run target: xmake run -, run = - { - -- xmake r - shortname = 'r' - - -- usage - , usage = "xmake run|r [options] [target] [arguments]" - - -- description - , description = "Run the project target." - - -- options - , options = - { - {'d', "debug", "k", nil, "Run and debug the given target." } - , {nil, "debugger", "kv", "auto", "Set the debugger path." } - - , {} - , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } - , {'P', "project", "kv", nil, "Change to the given project directory." - , "Search priority:" - , " 1. The Given Command Argument" - , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR" - , " 3. The Current Directory" } - , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } - - , {} - , {nil, "target", "v", nil, "Run the given target." } - , {nil, "arguments", "vs", nil, "The target arguments" } - } - } - - -- run lua: xmake lua -, lua = - { - -- xmake l - shortname = 'l' - - -- usage - , usage = "xmake lua|l [options] [script] [arguments]" - - -- description - , description = "Run the lua script." - - -- options - , options = - { - {'s', "string", "k", nil, "Run the lua string script." } - - , {} - , {'v', "verbose", "k", nil, "Print lots of verbose information." } - , {nil, "version", "k", nil, "Print the version number and exit." } - , {'h', "help", "k", nil, "Print this help message and exit." } - - , {} - , {nil, "script", "v", nil, "Run the given lua script." - , " - The script name from the xmake tool directory" - , " - The script file" - , " - The script string" } - , {nil, "arguments", "vs", nil, "The script arguments" } - } - } } -- prepare global diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua index 820ba4e6a..a6e26907f 100644 --- a/xmake/scripts/base/option.lua +++ b/xmake/scripts/base/option.lua @@ -25,10 +25,32 @@ local option = option or {} -- load modules local utils = require("base/utils") +local table = require("base/table") -- save the option menu function option._save_menu(menu) + -- translate the action menus if exists function + local submenus_all = {} + for k, submenu in pairs(menu) do + if type(submenu) == "function" then + local _submenus = submenu() + if _submenus then + for k, m in pairs(_submenus) do + submenus_all[k] = m + end + end + else + submenus_all[k] = submenu + end + end + table.copy2(menu, submenus_all) + + -- translate the actions of the main menu if exists function + if menu.main and type(menu.main.actions) == "function" then + menu.main.actions = menu.main.actions() + end + -- translate it if exists function in the option menu for _, submenu in pairs(menu) do diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index ea4924360..49432909d 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -68,7 +68,6 @@ function project._api_archs(env, ...) -- exists this architecture? for _, a in ipairs(table.join(...)) do - print(a, arch) if a and type(a) == "string" and a == arch then return true end diff --git a/xmake/scripts/base/table.lua b/xmake/scripts/base/table.lua index 1e0250bce..d6f6990d7 100644 --- a/xmake/scripts/base/table.lua +++ b/xmake/scripts/base/table.lua @@ -65,5 +65,33 @@ function table.join2(self, ...) return self end +-- clear the table +function table.clear(self) + + -- check + assert(self and type(self) == "table") + + -- clear it + for k in next, self do + rawset(self, k, nil) + end +end + +-- copy the table to self +function table.copy2(self, copied) + + -- check + assert(self and copied) + + -- clear self first + table.clear(self) + + -- copy it + for k, v in pairs(copied) do + self[k] = v + end + +end + -- return module: table return table |
