Guest User

free memory command for OpenComputers

a guest
Oct 7th, 2016
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.40 KB | None | 0 0
  1. local c = require("computer")
  2.  
  3. function round(num, idp)
  4.   if idp and idp>0 then
  5.     local mult = 10^idp
  6.     return math.floor(num * mult + 0.5) / mult
  7.   end
  8.   return math.floor(num + 0.5)
  9. end
  10.  
  11. function freeMemory()
  12.   local result = 0
  13.   for i = 1, 10 do
  14.     result = math.max(result, c.freeMemory())
  15.     os.sleep(0)
  16.   end
  17.   return result
  18. end
  19.  
  20. print(round(freeMemory() / 1024, 2), "kB free")
Add Comment
Please, Sign In to add comment