Simon's Graphics Blog

Work log for ideas and hobby projects.

A Lua Syntax Highlighter

with 3 comments

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.

Screenshot of lualite in Visual Studio 2003.

Screenshot of lualite in Visual Studio 2003.

Features

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.

Download

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

lualite-102-setup.exe

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.

lualite-source.zip

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.

Changelog

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.

Written by Simon Brown

June 21st, 2004 at 8:00 pm

Posted in C++,Lua

3 Responses to 'A Lua Syntax Highlighter'

Subscribe to comments with RSS or TrackBack to 'A Lua Syntax Highlighter'.

  1. I installed it to get true intellisense and was disappointed. It sucks cause lists all members it knows ignoring global objects semantics.Anyway, thanx for your job for free ;)

    slogic

    22 Feb 09 at 2:43 pm

  2. Yep the auto-completion is dumb, it doesn’t take any context into account. In order to do that I’d need to integrate the lua interpreter directly into the parser, which I didn’t really have the energy for. You have the source though, so feel free to improve things. :)

    Simon Brown

    1 Mar 09 at 3:38 pm

  3. Thanks so much! This is great!

    ncr

    18 Feb 10 at 12:01 am

Leave a Reply