Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int luaB_comemory (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
- luaL_argcheck(L, co, 1, "coroutine expected");
- size_t memory = sizeof(lua_State);
- /* Probing each individual type is ugly, but the only way that I see */
- int i;
- for (i = 1; lua_isnone(co, i) == 0; i++) {
- if (lua_isboolean(co, i)) {
- memory += sizeof(int);
- } else if (lua_iscfunction(co, i)) {
- memory += sizeof(lua_CFunction);
- } else if (lua_isfunction(co, i)) {
- memory += sizeof(Proto);
- } else if (lua_isnumber(co, i)) {
- memory += sizeof(lua_Number);
- } else if (lua_isstring(co, i)) {
- memory += lua_strlen(co, i);
- } else if (lua_istable(co, i)) {
- memory += 64; /* Temporary guess */
- } else if (lua_isthread(co, i)) {
- memory += sizeof(lua_State); /* Need to loop through thread */
- }
- }
- lua_pushinteger(L, (lua_Integer) memory);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement