Advertisement
Guest User

gpulib.lua

a guest
Jul 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local gpulib = {}
  2.  
  3. function gpulib.gpu()
  4.   return component.proxy(component.list("gpu")())
  5. end
  6.  
  7. function gpulib.print(value)
  8.   local cursorx = _G["cursorx"]
  9.   local cursory = _G["cursory"]
  10.   local gpu = gpulib.gpu()
  11.   local width = gpu.getViewport()
  12.   local str_len_left = value:len()
  13.   while str_len_left > 0 do
  14.     if str_len_left > width then
  15.       gpu.set(cursorx, cursory, value:sub(0, width))
  16.       value = value:sub(width+1)
  17.     else
  18.       gpu.set(cursorx, cursory, value:sub(0, str_len_left))
  19.       value = ""
  20.     end
  21.     cursory = cursory + 1
  22.     cursorx = 0
  23.   end
  24.   _G["cursorx"] = cursorx
  25.   _G["cursory"] = cursory
  26. end
  27.  
  28. function gpulib.cls()
  29.   local width, height = gpulib.gpu().getViewport()
  30.   gpulib.gpu().fill(0,0,width,heigth," ")
  31. end
  32.  
  33. return gpulib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement