summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-04-29 15:53:23 +0800
committerruki <[email protected]>2015-04-29 15:53:23 +0800
commitff6f56a46a77beb841fb22c185200ab0a833f05e (patch)
tree25e5df9267acb4013db504a3f7fea374e3e8ee28
parent47887f7de8de004290bd3c53d5536ed43c7e3f71 (diff)
load built-in scripts
-rw-r--r--[-rwxr-xr-x]core/build.sh3
-rwxr-xr-xcore/src/xmake/machine.c44
-rwxr-xr-xinstall6
-rw-r--r--xmake/scripts/_scripts.lua28
-rw-r--r--xmake/scripts/_xmake_main.lua47
-rw-r--r--xmake/scripts/base/prefix.lua43
-rw-r--r--xmake/scripts/xmake_main.lua8
7 files changed, 162 insertions, 17 deletions
diff --git a/core/build.sh b/core/build.sh
index 4eb828647..c9dc9292c 100755..100644
--- a/core/build.sh
+++ b/core/build.sh
@@ -4,4 +4,7 @@ if [ -f .config.mak ]; then
fi
make f DEBUG=n PLAT=msvc ARCH=x86
make r
+if [ $? -ne 0 ]; then
+ make o
+fi
exit
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 6e58f7d70..aad8e358b 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -83,6 +83,10 @@ static tb_bool_t xm_machine_main_save_arguments(xm_machine_impl_t* impl, tb_int_
// _ARGV = table_new
lua_setglobal(impl->lua, "_ARGV");
+ // enable verbose?
+ lua_pushboolean(impl->lua, impl->verbose);
+ lua_setglobal(impl->lua, "_VERBOSE");
+
// ok
return tb_true;
}
@@ -183,6 +187,10 @@ xm_machine_ref_t xm_machine_init()
// TODO: bind lua interfaces
// ...
+ // init namespace: xmake
+ lua_newtable(impl->lua);
+ lua_setglobal(impl->lua, "xmake");
+
// init verbose
impl->verbose = tb_false;
@@ -231,7 +239,7 @@ tb_int_t xm_machine_main(xm_machine_ref_t machine, tb_int_t argc, tb_char_t** ar
if (!xm_machine_main_get_program_directory(impl, path, sizeof(path))) return -1;
// append the main script path
- tb_strcat(path, "/scripts/xmake_main.lua");
+ tb_strcat(path, "/scripts/_xmake_main.lua");
// exists this script?
if (!tb_file_info(path, tb_null))
@@ -244,16 +252,36 @@ tb_int_t xm_machine_main(xm_machine_ref_t machine, tb_int_t argc, tb_char_t** ar
// trace
tb_trace_d("main: %s", path);
- // exec the script file
- tb_int_t error = luaL_dofile(impl->lua, path);
+ // load and execute the main script
+ if (luaL_dofile(impl->lua, path))
+ {
+ // trace
+ if (impl->verbose) tb_trace_i("%s", lua_tostring(impl->lua, -1));
+
+ // failed
+ return -1;
+ }
- // failed? print the error info
- if (error && impl->verbose)
+ // set the error function
+ tb_int_t errfunc = 0;
+ if (impl->verbose)
+ {
+ lua_getglobal(impl->lua, "debug");
+ lua_getfield(impl->lua, -1, "traceback");
+ errfunc = -2;
+ }
+
+ // call the main function
+ lua_getglobal(impl->lua, "_xmake_main");
+ if (lua_pcall(impl->lua, 0, 1, errfunc))
{
// trace
- tb_trace_i("%s", lua_tostring(impl->lua, -1));
+ if (impl->verbose) tb_trace_i("%s", lua_tostring(impl->lua, -1));
+
+ // failed
+ return -1;
}
- // ok?
- return error;
+ // get the error code
+ return (tb_int_t)lua_tonumber(impl->lua, -1);
}
diff --git a/install b/install
index 324f70d23..3dfa087b8 100755
--- a/install
+++ b/install
@@ -44,7 +44,11 @@ make f DEBUG=$debug > ../install.log
if [ $? -ne 0 ]; then exit; fi
make c >> ../install.log
make >> ../install.log
-if [ $? -ne 0 ]; then exit; fi
+if [ $? -ne 0 ]; then
+ make e
+ exit;
+fi
+make i
cd ..
# create the xmake install directory
diff --git a/xmake/scripts/_scripts.lua b/xmake/scripts/_scripts.lua
new file mode 100644
index 000000000..5fc0b8edb
--- /dev/null
+++ b/xmake/scripts/_scripts.lua
@@ -0,0 +1,28 @@
+--!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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- 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
new file mode 100644
index 000000000..13835b8f2
--- /dev/null
+++ b/xmake/scripts/_xmake_main.lua
@@ -0,0 +1,47 @@
+--!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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file _xmake_main.lua
+--
+
+-- init namespace: xmake
+xmake = xmake or {}
+
+-- init some global variables for xmake
+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
+
+-- load built-in scripts
+local scripts = dofile(xmake._SCRIPTS_DIR .. "_scripts.lua")
+for i = 1, #scripts do
+ dofile(xmake._SCRIPTS_DIR .. scripts[i])
+end
+
+-- the main entry function
+function _xmake_main()
+ xmake.trace("hello world!");
+ return 0
+end
diff --git a/xmake/scripts/base/prefix.lua b/xmake/scripts/base/prefix.lua
new file mode 100644
index 000000000..3784e9433
--- /dev/null
+++ b/xmake/scripts/base/prefix.lua
@@ -0,0 +1,43 @@
+--!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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- 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/xmake_main.lua b/xmake/scripts/xmake_main.lua
deleted file mode 100644
index 79623adfe..000000000
--- a/xmake/scripts/xmake_main.lua
+++ /dev/null
@@ -1,8 +0,0 @@
-
-print("_PROGRAM_DIR: ", _PROGRAM_DIR)
-print("_PROJECT_DIR: ", _PROJECT_DIR)
-
-for _, b in pairs(_ARGV) do
- print(b)
-end
-