troubles getting wxStyledTextCtrl to highlight lua syntax

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Haniskeczko
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Jan 24, 2022 10:02 pm

troubles getting wxStyledTextCtrl to highlight lua syntax

Post by Haniskeczko »

Image

https://ibb.co/VV0HKQn
This is the sample result of my configuration.
Keywords seems to not be highlighted.

Anyone has a solution? I tried to read LUA examples and the result below is something that is almost 1:1 copy

I have no clue why it wouldn't work. Even just leaving setKeywords line won't work. Please help :shock:

Code: Select all

    editor_->StyleResetDefault();
    editor_->StyleSetSize(wxSTC_STYLE_DEFAULT, 10);
    editor_->StyleClearAll();

    editor_->SetTabWidth(4);

    editor_->SetMarginWidth(0, 30);
    editor_->StyleSetForeground(wxSTC_STYLE_LINENUMBER, wxColour(75, 75, 75));
    editor_->StyleSetBackground(wxSTC_STYLE_LINENUMBER, wxColour(220, 220, 220));
    editor_->SetMarginType(0, wxSTC_MARGIN_NUMBER);


    editor_->StyleSetForeground(wxSTC_LUA_DEFAULT, wxColour(0, 0, 0));
    editor_->StyleSetForeground(wxSTC_LUA_COMMENT, wxColour(0, 127, 0));
    editor_->StyleSetForeground(wxSTC_LUA_COMMENTLINE, wxColour(0, 127, 0));
    editor_->StyleSetForeground(wxSTC_LUA_NUMBER, wxColour(0, 0, 127));
    editor_->StyleSetForeground(wxSTC_LUA_WORD, wxColour(0, 0, 255));
    editor_->StyleSetForeground(wxSTC_LUA_WORD2, wxColour(0, 128, 192));
    editor_->StyleSetForeground(wxSTC_LUA_WORD3, wxColour(128, 0, 255));
    editor_->StyleSetForeground(wxSTC_LUA_WORD4, wxColour(0, 0, 160));

    editor_->StyleSetForeground(wxSTC_LUA_STRING, wxColour(255, 0, 0));
    editor_->StyleSetForeground(wxSTC_LUA_CHARACTER, wxColour(255, 0, 0));
    editor_->StyleSetForeground(wxSTC_LUA_LITERALSTRING, wxColour(222, 0, 0));
    editor_->StyleSetForeground(wxSTC_LUA_STRINGEOL, wxColour(111, 0, 0));

    editor_->StyleSetForeground(wxSTC_LUA_OPERATOR, wxColour(0, 0, 160));
    editor_->StyleSetForeground(wxSTC_LUA_PREPROCESSOR, wxColour(255, 0, 0));
    editor_->SetWordChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

    editor_->StyleSetBold(wxSTC_LUA_WORD, true);
    editor_->StyleSetBold(wxSTC_LUA_NUMBER, true);

    editor_->SetKeyWords(0, "and break do else elseif end for function if in local nil not or repeat return then until while false true goto");
    editor_->SetKeyWords(1, "assert collectgarbage dofile error _G getmetatable ipairs loadfile next pairs pcall print rawequal rawget rawset setmetatable tonumber tostring type _VERSION xpcall string table math coroutine io os debug getfenv gcinfo load loadlib loadstring require select setfenv unpack _LOADED LUA_PATH _REQUIREDNAME package rawlen package bit32 utf8 _ENV");
    // String Manipulation & Mathematical
    editor_->SetKeyWords(2, "string.byte string.char string.dump string.find string.format string.gsub string.len string.lower string.rep string.sub string.upper table.concat table.insert table.remove table.sort math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.deg math.exp math.floor math.frexp math.ldexp math.log math.max math.min math.pi math.pow math.rad math.random math.randomseed math.sin math.sqrt math.tan string.gfind string.gmatch string.match string.reverse string.pack string.packsize string.unpack table.foreach table.foreachi table.getn table.setn table.maxn table.pack table.unpack table.move math.cosh math.fmod math.huge math.log10 math.modf math.mod math.sinh math.tanh math.maxinteger math.mininteger math.tointeger math.type math.ult bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.bxor bit32.extract bit32.replace bit32.lrotate bit32.lshift bit32.rrotate bit32.rshift utf8.char utf8.charpattern utf8.codes utf8.codepoint utf8.len utf8.offset");
    // Input and Output Facilities and System Facilities
    editor_->SetKeyWords(3, "coroutine.create coroutine.resume coroutine.status coroutine.wrap coroutine.yield io.close io.flush io.input io.lines io.open io.output io.read io.tmpfile io.type io.write io.stdin io.stdout io.stderr os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname coroutine.isyieldable coroutine.running io.popen module package.loaders package.seeall package.config package.searchers package.searchpath require package.cpath package.loaded package.loadlib package.path package.preload");
    editor_->SetLexer(wxSTC_LEX_LUA);
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: troubles getting wxStyledTextCtrl to highlight lua syntax

Post by doublemax »

Platform, wxWidgets version?

I've never used wxSTC, so unfortunately i can't help. There are a few other threads that deal with wxSTC lexers, maybe you can find some useful information there?

viewtopic.php?f=1&t=46161
viewtopic.php?f=1&t=47519
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: troubles getting wxStyledTextCtrl to highlight lua syntax

Post by ONEEYEMAN »

Hi,
Does stc sample works for you?

Thank you.
Haniskeczko
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Jan 24, 2022 10:02 pm

Re: troubles getting wxStyledTextCtrl to highlight lua syntax

Post by Haniskeczko »

Thanks for answers.
After taking a look into examples i have noticed that SetLexer function was called first. When i moved SetLexer to be the very first action on wxStyledTextCtrl it all started to work
Post Reply