summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-04-29 17:03:35 +0800
committerruki <[email protected]>2015-04-29 17:03:35 +0800
commit84999518105e894be127ceb3237a3d260f23cda9 (patch)
tree73fdb3b3c6c96264cc072b94cc2e79ad565962c2 /xmake/scripts
parentff6f56a46a77beb841fb22c185200ab0a833f05e (diff)
add main and utils modules
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/_xmake_main.lua21
-rw-r--r--xmake/scripts/base/main.lua (renamed from xmake/scripts/_scripts.lua)22
-rw-r--r--xmake/scripts/base/utils.lua (renamed from xmake/scripts/base/prefix.lua)16
3 files changed, 33 insertions, 26 deletions
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/_scripts.lua b/xmake/scripts/base/main.lua
index 5fc0b8edb..a049bee11 100644
--- a/xmake/scripts/_scripts.lua
+++ b/xmake/scripts/base/main.lua
@@ -17,12 +17,20 @@
-- Copyright (C) 2009 - 2015, ruki All rights reserved.
--
-- @author ruki
--- @file _scripts.lua
+-- @file main.lua
--
--- all built-in scripts list
-return
-{
- -- base
- "base/prefix.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/utils.lua
index 3784e9433..59769c260 100644
--- a/xmake/scripts/base/prefix.lua
+++ b/xmake/scripts/base/utils.lua
@@ -17,27 +17,33 @@
-- Copyright (C) 2009 - 2015, ruki All rights reserved.
--
-- @author ruki
--- @file prefix.lua
+-- @file utils.lua
--
+-- define module: utils
+local utils = {}
+
-- the trace function
-function xmake.trace(msg, ...)
+function utils.trace(msg, ...)
print(string.format(msg, ...))
end
-- the verbose function
-function xmake.verbose(msg, ...)
+function utils.verbose(msg, ...)
if xmake._VERBOSE then
print(string.format(msg, ...))
end
end
-- the error function
-function xmake.error(msg, ...)
+function utils.error(msg, ...)
print("error: " .. string.format(msg, ...))
end
-- the warning function
-function xmake.warning(msg, ...)
+function utils.warning(msg, ...)
print("warning: " .. string.format(msg, ...))
end
+
+-- return module: utils
+return utils