summaryrefslogtreecommitdiff
path: root/xmake/core/base/libc.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-19 23:48:25 +0800
committerruki <[email protected]>2021-09-19 23:48:25 +0800
commit33b05eff154f9158a68b0808f4be0f6c88aa6361 (patch)
treee1237eaf2a55ded0f55823562a712fd4cac0c1a8 /xmake/core/base/libc.lua
parent974ae1de229ee3077c868da14adebc11ddac42ac (diff)
add libc module
Diffstat (limited to 'xmake/core/base/libc.lua')
-rw-r--r--xmake/core/base/libc.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/xmake/core/base/libc.lua b/xmake/core/base/libc.lua
new file mode 100644
index 000000000..bac224df3
--- /dev/null
+++ b/xmake/core/base/libc.lua
@@ -0,0 +1,47 @@
+--!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 libc.lua
+--
+
+-- define module: libc
+local libc = libc or {}
+
+-- save original interfaces
+libc._malloc = libc._malloc or libc.malloc
+
+-- load modules
+local ffi = xmake._LUAJIT and require("ffi")
+
+-- define ffi interfaces
+if ffi then
+ ffi.cdef[[
+ void* malloc(size_t size);
+ void free(void* data);
+ ]]
+end
+
+function libc.malloc(size)
+ if ffi then
+ return ffi.cast("unsigned char*", ffi.C.malloc(size))
+ else
+ return libc._malloc(size)
+ end
+end
+
+-- return module: libc
+return libc