From 84999518105e894be127ceb3237a3d260f23cda9 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 29 Apr 2015 17:03:35 +0800 Subject: add main and utils modules --- xmake/scripts/_scripts.lua | 28 ------------------------- xmake/scripts/_xmake_main.lua | 21 +++++++------------ xmake/scripts/base/main.lua | 36 +++++++++++++++++++++++++++++++ xmake/scripts/base/prefix.lua | 43 ------------------------------------- xmake/scripts/base/utils.lua | 49 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 85 deletions(-) delete mode 100644 xmake/scripts/_scripts.lua create mode 100644 xmake/scripts/base/main.lua delete mode 100644 xmake/scripts/base/prefix.lua create mode 100644 xmake/scripts/base/utils.lua diff --git a/xmake/scripts/_scripts.lua b/xmake/scripts/_scripts.lua deleted file mode 100644 index 5fc0b8edb..000000000 --- a/xmake/scripts/_scripts.lua +++ /dev/null @@ -1,28 +0,0 @@ ---!The Automatic Cross-platform Build Tool --- --- XMake is free software; you can redistribute it and/or modify --- it under the terms of the GNU Lesser General Public License as published by --- the Free Software Foundation; either version 2.1 of the License, or --- (at your option) any later version. --- --- XMake is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Lesser General Public License for more details. --- --- You should have received a copy of the GNU Lesser General Public License --- along with XMake; --- If not, see http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _scripts.lua --- - --- all built-in scripts list -return -{ - -- base - "base/prefix.lua" -} diff --git a/xmake/scripts/_xmake_main.lua b/xmake/scripts/_xmake_main.lua index 13835b8f2..870f36276 100644 --- a/xmake/scripts/_xmake_main.lua +++ b/xmake/scripts/_xmake_main.lua @@ -21,27 +21,20 @@ -- -- init namespace: xmake -xmake = xmake or {} - --- init some global variables for xmake +xmake = xmake or {} xmake._ARGV = _ARGV xmake._VERBOSE = _VERBOSE xmake._PROGRAM_DIR = _PROGRAM_DIR xmake._PROJECT_DIR = _PROJECT_DIR xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts/" --- init namespace: xmake.main -xmake.main = {} -local main = xmake.main +-- init package path +package.path = xmake._SCRIPTS_DIR .. "?.lua;" .. package.path --- load built-in scripts -local scripts = dofile(xmake._SCRIPTS_DIR .. "_scripts.lua") -for i = 1, #scripts do - dofile(xmake._SCRIPTS_DIR .. scripts[i]) -end +-- load modules +local main = require("base/main") --- the main entry function +-- the main function function _xmake_main() - xmake.trace("hello world!"); - return 0 + return main.done() end diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua new file mode 100644 index 000000000..a049bee11 --- /dev/null +++ b/xmake/scripts/base/main.lua @@ -0,0 +1,36 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file main.lua +-- + +-- define module: main +local main = {} + +-- load modules +local utils = require("base/utils") + +-- the main function +function main.done() + utils.trace("hello world!") + return 0 +end + +-- return module: main +return main diff --git a/xmake/scripts/base/prefix.lua b/xmake/scripts/base/prefix.lua deleted file mode 100644 index 3784e9433..000000000 --- a/xmake/scripts/base/prefix.lua +++ /dev/null @@ -1,43 +0,0 @@ ---!The Automatic Cross-platform Build Tool --- --- XMake is free software; you can redistribute it and/or modify --- it under the terms of the GNU Lesser General Public License as published by --- the Free Software Foundation; either version 2.1 of the License, or --- (at your option) any later version. --- --- XMake is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Lesser General Public License for more details. --- --- You should have received a copy of the GNU Lesser General Public License --- along with XMake; --- If not, see http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file prefix.lua --- - --- the trace function -function xmake.trace(msg, ...) - print(string.format(msg, ...)) -end - --- the verbose function -function xmake.verbose(msg, ...) - if xmake._VERBOSE then - print(string.format(msg, ...)) - end -end - --- the error function -function xmake.error(msg, ...) - print("error: " .. string.format(msg, ...)) -end - --- the warning function -function xmake.warning(msg, ...) - print("warning: " .. string.format(msg, ...)) -end diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua new file mode 100644 index 000000000..59769c260 --- /dev/null +++ b/xmake/scripts/base/utils.lua @@ -0,0 +1,49 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file utils.lua +-- + +-- define module: utils +local utils = {} + +-- the trace function +function utils.trace(msg, ...) + print(string.format(msg, ...)) +end + +-- the verbose function +function utils.verbose(msg, ...) + if xmake._VERBOSE then + print(string.format(msg, ...)) + end +end + +-- the error function +function utils.error(msg, ...) + print("error: " .. string.format(msg, ...)) +end + +-- the warning function +function utils.warning(msg, ...) + print("warning: " .. string.format(msg, ...)) +end + +-- return module: utils +return utils -- cgit v1.3.1