Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. static int luaB_comemory (lua_State *L) {
  2. lua_State *co = lua_tothread(L, 1);
  3. luaL_argcheck(L, co, 1, "coroutine expected");
  4.  
  5. size_t memory = sizeof(lua_State);
  6.  
  7. /* Probing each individual type is ugly, but the only way that I see */
  8. int i;
  9.  
  10. for (i = 1; lua_isnone(co, i) == 0; i++) {
  11. int type = lua_type(co, i);
  12.  
  13. switch (type) {
  14. case LUA_TBOOLEAN:
  15. memory += sizeof(int);
  16. break;
  17.  
  18. case LUA_TFUNCTION:
  19. if (lua_iscfunction(co, i))
  20. memory += sizeof(lua_CFunction);
  21. else
  22. memory += sizeof(Proto);
  23. break;
  24.  
  25. case LUA_TNUMBER:
  26. memory += sizeof(lua_Number);
  27. break;
  28.  
  29. case LUA_TSTRING:
  30. memory += lua_strlen(co, i);
  31. break;
  32.  
  33. case LUA_TTABLE:
  34. memory += 64; /* Temporary guess */
  35. break;
  36.  
  37. case LUA_TTHREAD:
  38. memory += sizeof(lua_State); /* Need to loop through thread */
  39. break;
  40. }
  41. }
  42.  
  43. lua_pushinteger(L, (lua_Integer) memory);
  44.  
  45. return 1;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement