summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/engine.c2
-rw-r--r--core/src/xmake/libc/memcpy.c53
-rw-r--r--core/src/xmake/makefile3
3 files changed, 57 insertions, 1 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index dcfdd428c..2aa8f17cd 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -224,6 +224,7 @@ tb_int_t xm_semver_select(lua_State* lua);
// the libc functions
tb_int_t xm_libc_malloc(lua_State* lua);
tb_int_t xm_libc_free(lua_State* lua);
+tb_int_t xm_libc_memcpy(lua_State* lua);
#ifdef XM_CONFIG_API_HAVE_CURSES
// register curses
@@ -421,6 +422,7 @@ static luaL_Reg const g_libc_functions[] =
{
{ "malloc", xm_libc_malloc }
, { "free", xm_libc_free }
+, { "memcpy", xm_libc_memcpy }
, { tb_null, tb_null }
};
diff --git a/core/src/xmake/libc/memcpy.c b/core/src/xmake/libc/memcpy.c
new file mode 100644
index 000000000..e2c9af4c3
--- /dev/null
+++ b/core/src/xmake/libc/memcpy.c
@@ -0,0 +1,53 @@
+/*!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 memcpy.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "memcpy"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_libc_memcpy(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // check arguments?
+ if (!xm_lua_ispointer(lua, 1) || !xm_lua_ispointer(lua, 2) || !lua_isnumber(lua, 3))
+ xm_libc_return_error(lua, "memcpy(invalid args)!");
+
+ // do memcpy
+ tb_pointer_t dst = (tb_pointer_t)xm_lua_topointer(lua, 1);
+ tb_pointer_t src = (tb_pointer_t)xm_lua_topointer(lua, 2);
+ tb_int_t size = (tb_int_t)lua_tointeger(lua, 3);
+ if (dst && src && size > 0)
+ tb_memcpy(dst, src, size);
+ return 0;
+}
+
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index bd8046c67..3db867eb7 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -117,7 +117,8 @@ xmake_C_FILES += \
readline/add_history \
readline/clear_history \
libc/malloc \
- libc/free
+ libc/free \
+ libc/memcpy
iswin =
ifeq ($(PLAT),windows)