Visual Studio Code + Lua
Solution 1
For custom syntax highlighting and code completion.
In VSCode, install extension: Lua by sumneko
I don't know how to properly use emmyLua so my example is not perfect, but it's easy to setup with minimal effort. My use case is NLua integrated in C#. Just need to edit files with some code completion.
create file: Demo.lua
-- set the class a dummy name, since creator is the same name
-- eg. class name Point, creator name also Point will work
-- but will result in messy suggestions
---@class cPoint
---@field X number
---@field Y number
-- creator
---@type fun( x:number, y:number ) : cPoint
Point = {};
---@class Shapes
---@field Origin cPoint
local Shapes = nil;
---@type fun( x:number, y:number )
function Shapes:Move( x, y ) end
---@class cCircle : Shapes
---@field Radius number
local cCircle = {}; -- define to be able to ...
---@type fun( angle:number )
function cCircle:Roll( angle ) end -- ... add methods
---@type fun( x:number, y:number, r:number ) : cCircle
Circle = {};
---@class cRectangle:Shapes
---@field Width number
---@field Height number
local cRectangle = {};
---@type fun( origin:cPoint, w:number, h:number ) : cRectangle
Rectangle = nil;
-- no method overload, so just force it
---@type fun( x:number, y:number, w:number, h:number ) : cRectangle
Rectangle = nil;
create another file: test.lua
c = Circle( 10, 10, 10 );
c.Origin.X = 10;
c.Move( 10, 10 );
c.Roll( 10 );
r = Rectangle( Point( 0, 0 ), 10, 10 );
r = Rectangle( 10, 10, 10, 10 );
-- DETECTED ERRORS
c.origin.X = 10;
s = Shapes();
r.Roll( 10 );
-- NOT DETECTED
r = Rectangle( "hello" );
c = Circle(10,10);
c = Circle();
c.Roll();
Rectangle()
Solution 2
Three years later and we have vscode-lua. From what I gather it has some kind of Intellisense and could possibly pe configured to find paths to the needed libraries, version specification (5.1, 5.2, 5.3), indent, line-width and other formatting related things... Give it a try!
TyKonKet
Updated on June 04, 2022Comments
-
TyKonKet almost 2 years
From what I can see, currently Visual Studio Code for Lua supports only syntax colorization and we can have formatting and some snippets with extensions. What I need to know is if there are or is planned some kind of Intellisense.