Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. for k, v in pairs(file) do
  2.         local y = k * font:getHeight(" ")
  3.         local x = 0
  4.         local string = v
  5.         local words = {}
  6.  
  7.         for w in string:gmatch("%S+") do table.insert(words, w) end
  8.  
  9.         while string:len() > 0 do
  10.             local index = string:find(" ") or string:len()+1
  11.             local char = string:sub(1, 1)
  12.  
  13.             if index == 1 or char == "(" or char == ")" or char == '"' then
  14.                 love.graphics.setColor(0, 0, 0)
  15.                 if char == "(" then
  16.                     love.graphics.print("(", x, y)
  17.                     isFunction = false
  18.                 elseif char == ")" then
  19.                     love.graphics.print(")", x, y)
  20.                     isFunction = false
  21.                 elseif char == '"' then
  22.                     love.graphics.setColor(unpack(theme["string"]))
  23.                     love.graphics.print('"', x, y)
  24.                     isString = (not isString)
  25.                 end
  26.  
  27.                 string = string:sub(2)
  28.                 x = x + font:getWidth(" ")
  29.             else
  30.                 local word = string:sub(1, index-1)
  31.                 local key = word
  32.  
  33.                 if isString then
  34.                     love.graphics.setColor(unpack(theme["string"]))
  35.                 elseif isFunction then
  36.                     love.graphics.setColor(unpack(theme["newFunction"]))
  37.                     isFunction = false
  38.                 else
  39.                     if tonumber(word) ~= nil then
  40.                         love.graphics.setColor(unpack(theme["constant"]))
  41.                     elseif keywords[key] then
  42.                         love.graphics.setColor(unpack(theme[keywords[key]] ) )
  43.                     else
  44.                         love.graphics.setColor( unpack( theme.normal ) )
  45.                     end
  46.  
  47.                     if word == "function" then
  48.                         isFunction = true
  49.                     else
  50.                         isFunction = false
  51.                     end
  52.                 end
  53.  
  54.                 love.graphics.print(word, x, y)
  55.  
  56.                 x = x + font:getWidth(word)
  57.                 string = string:sub(word:len()+1)
  58.             end
  59.         end
  60.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement