Advertisement
Guest User

Untitled

a guest
May 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1.  
  2. local function lookupIndexInStyle(index, style)
  3. for part in index:gmatch "[^%.]+" do
  4. style = style[part] or style._Default or style
  5. end
  6. return style._Default or style
  7. end
  8.  
  9. local function renderText(text, style, x, y)
  10. local i = 1
  11. local cstack = { lookupIndexInStyle( "_Default", style ) }
  12. local tstack = { "" }
  13. local list = {}
  14.  
  15. if text:sub( i, i ) == "{" then
  16. list[#list + 1] = { text = tstack[#tstack], colour = cstack[#cstack] }
  17. tstack[#tstack] = ""
  18. tstack[#tstack + 1] = ""
  19.  
  20. local name = text:match( "^(%w[%.%w]*%w):", i + 1 ) or text:match( "^(%w):", i + 1 ) or "" -- error instead here?
  21.  
  22. cstack[#cstack + 1] = lookupIndexInStyle( name, style )
  23. i = i + #name + 2 -- + 1 for '{' and ':'
  24. elseif text:sub( i, i ) == "}" then
  25. list[#list + 1] = { text = tstack[#tstack], colour = cstack[#cstack] }
  26. tstack[#tstack] = nil
  27. cstack[#cstack] = nil
  28. else
  29. tstack[#tstack] = tstack[#tstack] .. text:sub( i, i )
  30. end
  31.  
  32. list[#list + 1] = { text = tstack[1], colour = cstack[1] }
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement