Coloured Lua - Is it possible?

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

What do you mean with:

?

for example ‘local’ would be coloured red

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

thats kinda the question though

In studio

File (Top left hand corner) >> Studio Options >> Script Editor >> Scroll down to theme

change at will

nonononononnoo

i meant inside a textbox

You can use richtext.

And what does that do exactly?

It let’s you change text using markup tags.

how would you scan the text for certain words?

you can use string manipulation.

1 Like

I’m not good with tables so I can’t really help you sorry :sweat_smile:

You already have the library, just use it! Highlighter does exactly what you want.

So which one do i look at :skull:
looks super complex

Looking at the library, it does what you’re looking for. What exactly is not working?

1 Like

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:

image

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

Here is the module that @CrazyAlternetive is referring to:

lexer.lua (8.7 KB)

1 Like