Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 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. if (lua_isboolean(co, i)) {
  12. memory += sizeof(int);
  13. } else if (lua_iscfunction(co, i)) {
  14. memory += sizeof(lua_CFunction);
  15. } else if (lua_isfunction(co, i)) {
  16. memory += sizeof(Proto);
  17. } else if (lua_isnumber(co, i)) {
  18. memory += sizeof(lua_Number);
  19. } else if (lua_isstring(co, i)) {
  20. memory += lua_strlen(co, i);
  21. } else if (lua_istable(co, i)) {
  22. memory += 64; /* Temporary guess */
  23. } else if (lua_isthread(co, i)) {
  24. memory += sizeof(lua_State); /* Need to loop through thread */
  25. }
  26. }
  27.  
  28. lua_pushinteger(L, (lua_Integer) memory);
  29.  
  30. return 1;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement