forked from sanikoyes/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlua-memory.c
71 lines (55 loc) · 1.02 KB
/
lua-memory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include "malloc_hook.h"
#include "luashrtbl.h"
static int
ltotal(lua_State *L) {
size_t t = malloc_used_memory();
lua_pushinteger(L, (lua_Integer)t);
return 1;
}
static int
lblock(lua_State *L) {
size_t t = malloc_memory_block();
lua_pushinteger(L, (lua_Integer)t);
return 1;
}
static int
ldumpinfo(lua_State *L) {
memory_info_dump();
return 0;
}
static int
ldump(lua_State *L) {
dump_c_mem();
return 0;
}
static int
lexpandshrtbl(lua_State *L) {
int n = luaL_checkinteger(L, 1);
luaS_expandshr(n);
return 0;
}
static int
lcurrent(lua_State *L) {
lua_pushinteger(L, malloc_current_memory());
return 1;
}
LUAMOD_API int
luaopen_memory(lua_State *L) {
luaL_checkversion(L);
luaL_Reg l[] = {
{ "total", ltotal },
{ "block", lblock },
{ "dumpinfo", ldumpinfo },
{ "dump", ldump },
{ "info", dump_mem_lua },
{ "ssinfo", luaS_shrinfo },
{ "ssexpand", lexpandshrtbl },
{ "current", lcurrent },
{ NULL, NULL },
};
luaL_newlib(L,l);
return 1;
}