Simon’s Graphics Blog

A Lua Syntax Highlighter

· Read in about 3 min · (488 Words)
code lua

Lua is a very compact, fast scripting language with great platform support. Editing lua scripts is nice and easy in most editors (such as gvim, but Visual Studio doesn’t highlight the syntax by default. So here’s a plug-in for Visual Studio .NET 2003 that highlights Lua 5.0 syntax and provides auto-completion for keywords and identifiers as you type.



This syntax highlighter has the following features:

  • Can parse the full Lua 5.0 syntax.
  • Uses the Visual Studio .NET colours for text, keyword, string, number, operator and comment.
  • Provides auto-completion using all identifiers in the file - you get completion in strings and comments!
  • Automatically drops down completion candidates on the . or : key.
  • Small, fast, state-tracked parser - top speed even on large files.

The plug-in requires Visual Studio .NET 2003. It will not work with older versions.


Thanks to the fantastic Inno Setup, I’ve packaged the highlighter in a handy windows installer.


Download and run the installer to install the highlighting plug-in. Please note: installing this plug-in will reset your toolbars to their defaults. This is a “feature” of the registration process, and unfortunately cannot be avoided. Please don’t send me bug reports about this, I’m sorry but it cannot be fixed!

Source Code

If you’re interested in how the plug-in works, then feel free to download the full source. This code requires the Visual Studio .NET 2003 C++ compiler and the VSIP SDK to compile. It also does not come with any attached license, so feel free to hack about with it for whatever you like. Just be sure to generate your own GUIDs and apply for your own package load key before you release any plug-ins yourself.

The VSIP SDK comes with a framework for Language Services, called Babel, which is meant to be plugged into using a flex/bison grammar. The codebase for Babel is more than a little complicated… so this project doesn’t use it. The lualite source has been written from scratch using only the ATL and VSIP interface definitions, and as such is very lightweight and easily adaptable to other languages.

Known Bugs

Find In Files: A few users have reported a problem where the “Find In Files” feature of Visual Studio can lock up when lua files are open in the IDE. I’ve been unable to reproduce this bug locally, and am unsure of how the code could interact with this feature and cause the IDE to lock up. Any help with finding or fixing this bug would be most appreciated.


Version 1.0.2: (16/8/04)
* Moved from using stock colours to defining proper colourable items.
* Added support for lua operator highlighting using the "Operator" tag.
* The plug-in now presents itself as an installed product in the splash screen 
  and the about dialog.

Version 1.0.1: (21/7/04) 
* Fixed scanner bug where \\ within a string could cause incorrect highlighting.

Version 1.0: (21/6/04) 
* Initial release.