summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2024-10-25 00:44:03 +0800
committerruki <[email protected]>2024-10-25 00:44:03 +0800
commitc92b5d009f2421ee3cda1933c5cac519659785f1 (patch)
treee4563b150e4453727d531ca865b9f531a8c6a668 /core/src
parentdeb55641c247a86ed0321075977d9a067f73b00d (diff)
add native bin2c
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/engine.c13
-rw-r--r--core/src/xmake/utils/bin2c.c58
-rw-r--r--core/src/xmake/utils/prefix.h31
-rwxr-xr-xcore/src/xmake/xmake.sh1
4 files changed, 103 insertions, 0 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 5fab7e7c1..8753607d4 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -316,6 +316,9 @@ tb_int_t xm_tty_term_mode(lua_State* lua);
// the package functions
tb_int_t xm_package_loadxmi(lua_State* lua);
+// the utils functions
+tb_int_t xm_utils_bin2c(lua_State* lua);
+
#ifdef XM_CONFIG_API_HAVE_CURSES
// register curses functions
tb_int_t xm_lua_curses_register(lua_State* lua, tb_char_t const* module);
@@ -600,6 +603,13 @@ static luaL_Reg const g_package_functions[] =
, { tb_null, tb_null }
};
+// the utils functions
+static luaL_Reg const g_utils_functions[] =
+{
+ { "bin2c", xm_utils_bin2c }
+, { tb_null, tb_null }
+};
+
// the lua global instance for signal handler
static lua_State* g_lua = tb_null;
@@ -1364,6 +1374,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c
// bind package functions
xm_lua_register(engine->lua, "package", g_package_functions);
+ // bind utils functions
+ xm_lua_register(engine->lua, "utils", g_utils_functions);
+
#ifdef XM_CONFIG_API_HAVE_CURSES
// bind curses
xm_lua_curses_register(engine->lua, "curses");
diff --git a/core/src/xmake/utils/bin2c.c b/core/src/xmake/utils/bin2c.c
new file mode 100644
index 000000000..1ce85654c
--- /dev/null
+++ b/core/src/xmake/utils/bin2c.c
@@ -0,0 +1,58 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file bin2c.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "bin2c"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+/* generate c/c++ code from the binary file
+ *
+ * local ok, errors = utils.bin2c(binaryfile, outputfile, linewidth, nozeroend)
+ */
+tb_int_t xm_utils_bin2c(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the binaryfile
+ tb_char_t const* binaryfile = luaL_checkstring(lua, 1);
+ tb_check_return_val(binaryfile, 0);
+
+ // get the outputfile
+ tb_char_t const* outputfile = luaL_checkstring(lua, 2);
+ tb_check_return_val(outputfile, 0);
+
+ tb_trace_i("binaryfile: %s", binaryfile);
+ tb_trace_i("outputfile: %s", outputfile);
+
+ return 0;
+}
diff --git a/core/src/xmake/utils/prefix.h b/core/src/xmake/utils/prefix.h
new file mode 100644
index 000000000..e56baedf7
--- /dev/null
+++ b/core/src/xmake/utils/prefix.h
@@ -0,0 +1,31 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file prefix.h
+ *
+ */
+#ifndef XM_UTILS_PREFIX_H
+#define XM_UTILS_PREFIX_H
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "../prefix.h"
+
+#endif
+
+
diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh
index 62af5b2fa..8bcc60632 100755
--- a/core/src/xmake/xmake.sh
+++ b/core/src/xmake/xmake.sh
@@ -71,6 +71,7 @@ target "xmake"
add_files "semver/*.c"
add_files "string/*.c"
add_files "tty/*.c"
+ add_files "utils/*.c"
if is_plat "mingw"; then
add_files "winos/*.c"
fi