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++) {
- int type = lua_type(co, i);
- switch (type) {
- case LUA_TBOOLEAN:
- memory += sizeof(int);
- break;
- case LUA_TFUNCTION:
- if (lua_iscfunction(co, i))
- memory += sizeof(lua_CFunction);
- else
- memory += sizeof(Proto);
- break;
- case LUA_TNUMBER:
- memory += sizeof(lua_Number);
- break;
- case LUA_TSTRING:
- memory += lua_strlen(co, i);
- break;
- case LUA_TTABLE:
- memory += 64; /* Temporary guess */
- break;
- case LUA_TTHREAD:
- memory += sizeof(lua_State); /* Need to loop through thread */
- break;
- }
- }
- lua_pushinteger(L, (lua_Integer) memory);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement