summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2015-04-23 13:23:37 +0800
committerruki <[email protected]>2015-04-23 13:23:37 +0800
commitaea3dbeeeabd51d16a41d73a203f0467f8ad6cf0 (patch)
tree16c15df5765e095934e8662ec24220a576417c72 /core/src
parentbdcac40834aaebd4a9d52b607a42f593e8a85a3c (diff)
add machine interfaces
Diffstat (limited to 'core/src')
-rwxr-xr-xcore/src/demo/xmake.c20
-rwxr-xr-xcore/src/xmake/machine.c101
-rwxr-xr-xcore/src/xmake/machine.h75
-rwxr-xr-xcore/src/xmake/makefile4
-rwxr-xr-xcore/src/xmake/xmake.c14
-rwxr-xr-xcore/src/xmake/xmake.h5
6 files changed, 202 insertions, 17 deletions
diff --git a/core/src/demo/xmake.c b/core/src/demo/xmake.c
index 6b62933ef..5b69e36e3 100755
--- a/core/src/demo/xmake.c
+++ b/core/src/demo/xmake.c
@@ -8,23 +8,23 @@
*/
tb_int_t main(tb_int_t argc, tb_char_t** argv)
{
- // init tbox
-#if 0
- if (!tb_init(tb_null, (tb_byte_t*)malloc(300 * 1024 * 1024), 300 * 1024 * 1024)) return 0;
-#else
- if (!tb_init(tb_null, tb_null, 0)) return 0;
-#endif
-
// init xmake
if (!xm_init()) return 0;
+ // init machine
+ xm_machine_ref_t machine = xm_machine_init();
+ if (machine)
+ {
+ // done machine
+ xm_machine_main(machine, argc, argv, "xmake_main.lua");
+
+ // exit machine
+ xm_machine_exit(machine);
+ }
// exit xmake
xm_exit();
- // exit tbox
- tb_exit();
-
// ok?
return 0;
}
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
new file mode 100755
index 000000000..5ed83df09
--- /dev/null
+++ b/core/src/xmake/machine.c
@@ -0,0 +1,101 @@
+/*!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.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "xmake.h"
+#include "luajit/luajit.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * types
+ */
+
+// the machine impl type
+typedef struct __xm_machine_impl_t
+{
+ // the lua
+ lua_State* lua;
+
+}xm_machine_impl_t;
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+xm_machine_ref_t xm_machine_init()
+{
+ // done
+ tb_bool_t ok = tb_false;
+ xm_machine_impl_t* impl = tb_null;
+ do
+ {
+ // init machine
+ impl = tb_malloc0_type(xm_machine_impl_t);
+ tb_assert_and_check_break(impl);
+
+ // init lua
+ impl->lua = lua_open();
+ tb_assert_and_check_break(impl->lua);
+
+ // open lua libraries
+ luaL_openlibs(impl->lua);
+
+ // TODO
+ // ...
+
+ // ok
+ ok = tb_true;
+
+ } while (0);
+
+ // failed?
+ if (!ok)
+ {
+ // exit it
+ if (impl) xm_machine_exit((xm_machine_ref_t)impl);
+ impl = tb_null;
+ }
+
+ return (xm_machine_ref_t)impl;
+}
+tb_void_t xm_machine_exit(xm_machine_ref_t machine)
+{
+ // check
+ xm_machine_impl_t* impl = (xm_machine_impl_t*)machine;
+ tb_assert_and_check_return(impl);
+
+ // exit lua
+ if (impl->lua) lua_close(impl->lua);
+ impl->lua = tb_null;
+
+ // exit it
+ tb_free(impl);
+}
+tb_int_t xm_machine_main(xm_machine_ref_t machine, tb_int_t argc, tb_char_t** argv, tb_char_t const* code_path)
+{
+ // check
+ xm_machine_impl_t* impl = (xm_machine_impl_t*)machine;
+ tb_assert_and_check_return_val(impl && impl->lua && code_path, -1);
+
+ return 0;
+}
diff --git a/core/src/xmake/machine.h b/core/src/xmake/machine.h
new file mode 100755
index 000000000..a64999ef1
--- /dev/null
+++ b/core/src/xmake/machine.h
@@ -0,0 +1,75 @@
+/*!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 machine.h
+ *
+ */
+#ifndef XM_MACHINE_H
+#define XM_MACHINE_H
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * extern
+ */
+__tb_extern_c_enter__
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * types
+ */
+
+/// the xmake machine type
+typedef struct{}* xm_machine_ref_t;
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * interfaces
+ */
+
+/*! init the machine
+ *
+ * @return the machine
+ */
+xm_machine_ref_t xm_machine_init(tb_noarg_t);
+
+/*! exit the machine
+ *
+ * @param machine the machine
+ */
+tb_void_t xm_machine_exit(xm_machine_ref_t machine);
+
+/*! done the machine
+ *
+ * @param machine the machine
+ * @param argc the argument count of the console
+ * @param argv the argument list of the console
+ * @param code_path the main code file path
+ *
+ * @return the error code of main()
+ */
+tb_int_t xm_machine_main(xm_machine_ref_t machine, tb_int_t argc, tb_char_t** argv, tb_char_t const* code_path);
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * extern
+ */
+__tb_extern_c_leave__
+
+#endif
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 92499372a..394a48950 100755
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -12,7 +12,8 @@ xmake_CONFIG = y
# core files
xmake_C_FILES += \
- xmake
+ xmake \
+ machine
# flags
@@ -21,6 +22,7 @@ xmake_CXFLAGS += -D__tb_prefix__=\"xmake\"
# header files
xmake_INC_FILES = \
xmake.h \
+ machine.h \
config.h \
prefix.h \
prefix/prefix.h \
diff --git a/core/src/xmake/xmake.c b/core/src/xmake/xmake.c
index 196d1136b..a1f97fe4d 100755
--- a/core/src/xmake/xmake.c
+++ b/core/src/xmake/xmake.c
@@ -41,13 +41,13 @@ static __tb_inline__ tb_bool_t xm_check_mode(tb_size_t mode)
#ifdef __xm_debug__
if (!(mode & TB_MODE_DEBUG))
{
- tb_trace_e("libgbox.a has __tb_debug__ but xmake/xmake.h not");
+ tb_trace_e("libxmake.a has __tb_debug__ but xmake/xmake.h not");
return tb_false;
}
#else
if (mode & TB_MODE_DEBUG)
{
- tb_trace_e("xmake/xmake.h has __tb_debug__ but libgbox.a not");
+ tb_trace_e("xmake/xmake.h has __tb_debug__ but libxmake.a not");
return tb_false;
}
#endif
@@ -55,13 +55,13 @@ static __tb_inline__ tb_bool_t xm_check_mode(tb_size_t mode)
#ifdef __xm_small__
if (!(mode & TB_MODE_SMALL))
{
- tb_trace_e("libgbox.a has __tb_small__ but xmake/xmake.h not");
+ tb_trace_e("libxmake.a has __tb_small__ but xmake/xmake.h not");
return tb_false;
}
#else
if (mode & TB_MODE_SMALL)
{
- tb_trace_e("xmake/xmake.h has __tb_small__ but libgbox.a not");
+ tb_trace_e("xmake/xmake.h has __tb_small__ but libxmake.a not");
return tb_false;
}
#endif
@@ -106,6 +106,9 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build)
// check version
xm_version_check(build);
+ // init tbox
+ if (!tb_init(tb_null, tb_null, 0)) return tb_false;
+
// trace
tb_trace_d("init: ok");
@@ -120,6 +123,9 @@ tb_void_t xm_exit()
// check
tb_assert_and_check_return(!init);
+
+ // exit tbox
+ tb_exit();
}
tb_version_t const* xm_version()
{
diff --git a/core/src/xmake/xmake.h b/core/src/xmake/xmake.h
index a6253330b..bc08ea2d1 100755
--- a/core/src/xmake/xmake.h
+++ b/core/src/xmake/xmake.h
@@ -20,13 +20,14 @@
* @file xmake.h
*
*/
-#ifndef XM_GBOX_H
-#define XM_GBOX_H
+#ifndef XM_XMAKE_H
+#define XM_XMAKE_H
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "prefix.h"
+#include "machine.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* extern