Advertisement
AKopyl

p_util_fix

Mar 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. function fixPaintUtils()
  2.     local tColourLookup = {}
  3.     for n=1,16 do
  4.        tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
  5.     end
  6.  
  7.     local function parseLine( tImageArg, sLine )
  8.       local tLine = {}
  9.         for x=1,sLine:len() do
  10.           tLine[x] = tColourLookup[ string.byte(sLine,x,x) ] or 0
  11.       end
  12.       table.insert( tImageArg, tLine )
  13.     end
  14.  
  15.     function paintutils.loadImage( sPath )
  16.        if type( sPath ) ~= "string" then
  17.            error( "bad argument #1 (expected string, got " .. type( sPath ) .. ")", 2 )
  18.         end
  19.  
  20.         if fs.exists( sPath ) then
  21.             local file = io.open( sPath, "r" )
  22.            local sContent = file:read("*a")
  23.            file:close()
  24.            return paintutils.parseImage( sContent ) -- delegate image parse to parseImage
  25.         end
  26.         return nil
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement