saaawdust
(sawdust)
March 15, 2023, 9:35pm
#1
I know this is possible: GitHub - boatbomber/Highlighter: RichText highlighting Lua code with a pure Lua lexer
How do i do this with a textbox? I tried to git it but it doesn’t work. I tried to copy the files and i just get errors, Is this even possible at all?
I basically want the texts colour to change based on the lua
saaawdust
(sawdust)
March 15, 2023, 9:39pm
#3
for example ‘local’ would be coloured red
Dede_4242
(Dede_4242)
March 15, 2023, 9:39pm
#4
I guess you would create a table with all the certain words that are coloured in a certain way, check if it’s that word, and then change colour
saaawdust
(sawdust)
March 15, 2023, 9:42pm
#5
thats kinda the question though
In studio
File (Top left hand corner) >> Studio Options >> Script Editor >> Scroll down to theme
change at will
saaawdust
(sawdust)
March 15, 2023, 9:51pm
#9
And what does that do exactly?
It let’s you change text using markup tags.
saaawdust
(sawdust)
March 15, 2023, 9:52pm
#11
how would you scan the text for certain words?
you can use string manipulation.
1 Like
Dede_4242
(Dede_4242)
March 15, 2023, 9:55pm
#13
I’m not good with tables so I can’t really help you sorry
local_ip
(jmk)
March 15, 2023, 9:57pm
#14
You already have the library, just use it! Highlighter does exactly what you want.
saaawdust
(sawdust)
March 15, 2023, 10:01pm
#15
So which one do i look at
looks super complex
Looking at the library, it does what you’re looking for. What exactly is not working?
1 Like
saaawdust
(sawdust)
March 15, 2023, 10:04pm
#17
The Highlight one? Is that what you mean?
Yes it does exactly what you’re trying to do. As for your question, y ouneed to use this
<string>:match()
Ayy, I was fixing my old syntax highlighter and when I was finished, this came up!
But yes, it is possible:
All you need is the Lexer module as it does most of the work for you. (Saves you from the pain lol)
And you do something like this:
-- Highlighter
function module:highlightText(display, input)
local source = input.Text
display.Text = ""
for token, keyword in lexer.scan(source) do
local syntaxColor = syntaxColors[token]
if syntaxColor then
display.Text = display.Text .. textColorizer:colorize(keyword, syntaxColor)
else
display.Text = display.Text .. keyword
end
end
displayFix:fixText(display)
end
skeliphant
(skeliphant)
March 15, 2023, 10:19pm
#20
Here is the module that @CrazyAlternetive is referring to:
lexer.lua (8.7 KB)
1 Like