summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-27 22:44:21 +0800
committerruki <[email protected]>2022-07-27 22:44:21 +0800
commit557b2bf7b8326ecc440db1d67617bc8bae62959d (patch)
tree874de72378ff0ce16228131159926b63142db12e /core/src
parentf7d9c1714f894fa04077cebbe7299eaa9b8070bf (diff)
add os.meminfo
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/engine.c2
-rw-r--r--core/src/xmake/makefile1
-rw-r--r--core/src/xmake/os/meminfo.c51
3 files changed, 54 insertions, 0 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 7c904fb38..6458dee1c 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -106,6 +106,7 @@ tb_int_t xm_os_setenv(lua_State* lua);
tb_int_t xm_os_getenv(lua_State* lua);
tb_int_t xm_os_getenvs(lua_State* lua);
tb_int_t xm_os_cpuinfo(lua_State* lua);
+tb_int_t xm_os_meminfo(lua_State* lua);
tb_int_t xm_os_readlink(lua_State* lua);
tb_int_t xm_os_filesize(lua_State* lua);
tb_int_t xm_os_emptydir(lua_State* lua);
@@ -326,6 +327,7 @@ static luaL_Reg const g_os_functions[] =
, { "getenv", xm_os_getenv }
, { "getenvs", xm_os_getenvs }
, { "cpuinfo", xm_os_cpuinfo }
+, { "meminfo", xm_os_meminfo }
, { "readlink", xm_os_readlink }
, { "emptydir", xm_os_emptydir }
, { "strerror", xm_os_strerror }
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 5d017f0b0..44fb9a0b3 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -38,6 +38,7 @@ xmake_C_FILES += \
os/getenv \
os/getenvs \
os/cpuinfo \
+ os/meminfo \
os/readlink \
os/emptydir \
os/syserror \
diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c
new file mode 100644
index 000000000..904d0797f
--- /dev/null
+++ b/core/src/xmake/os/meminfo.c
@@ -0,0 +1,51 @@
+/*!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 meminfo.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "meminfo"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+tb_int_t xm_os_meminfo(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ lua_newtable(lua);
+
+ // get pagesize
+ tb_int_t pagesize = (tb_int_t)tb_page_size();
+ lua_pushstring(lua, "pagesize");
+ lua_pushinteger(lua, pagesize > 0? pagesize : 1);
+ lua_settable(lua, -3);
+
+ return 1;
+}