Lua auto-complete?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Lua auto-complete?

Post by paulclinger »

Desty wrote:Could you elaborate on how you got lua-inspect to work? I installed it in Vim and it reports a series of errors like this:
This is indeed because love is a global variable that is set by the environment. I haven't "fixed" this problem in any way, but I wrote my own walker to report the errors the way I'd like to see them. Essentially, it works like this: metalua is used to build Abstract Syntax Tree (AST) for a file, lua-inspect then traverses that AST to identify and mark nodes that can correspond to various conditions it checks, ZeroBrane Studio then traverses that modified AST (the code is in src/editor/inspect.lua) to report the errors.

Some of the modifications I made were around reporting only first changes to global variables to minimize the number of errors:

- first use of unknown global function '...'
- first use of unknown global variable '...'
- first assignment to global variable '...'

lua-inspect also includes --! syntax to provide hints to the module, but I can't find documentation for all the commands it supports. I also have a ticket in ZBS to provide similar syntax to turn reporting off for some variables or some error types.
Desty
Prole
Posts: 4
Joined: Sat Oct 27, 2012 7:26 pm
Location: Ireland

Re: Lua auto-complete?

Post by Desty »

paulclinger wrote:This is indeed because love is a global variable that is set by the environment. I haven't "fixed" this problem in any way, but I wrote my own walker to report the errors the way I'd like to see them. Essentially, it works like this: metalua is used to build Abstract Syntax Tree (AST) for a file, lua-inspect then traverses that AST to identify and mark nodes that can correspond to various conditions it checks, ZeroBrane Studio then traverses that modified AST (the code is in src/editor/inspect.lua) to report the errors.
Nice :) I didn't know the AST would retain useful information about the scope of variables etc. My only experience with such structures was a couple of assignments based on Appel's compiler book a few years back, and it was mostly on (essentially) a toy dialect of Java.

A quick browse through the Love2D source tarball didn't show a convenient "love.lua"; rather it seems that the Love interpreter front-end bundles together a bunch of C functions and makes them available like a normal module?

But maybe I could extract the API info from somewhere else (like the wiki) and make a dummy love.lua which just contains dummy methods like the following, to give lua-inspect enough info for useful auto-completion:

Code: Select all

love = love or { physics={newWorld=function(width, height) end} }
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Lua auto-complete?

Post by paulclinger »

Desty wrote:But maybe I could extract the API info from somewhere else (like the wiki) and make a dummy love.lua which just contains dummy methods like the following, to give lua-inspect enough info for useful auto-completion:

Code: Select all

love = love or { physics={newWorld=function(width, height) end} }
Yes, you can definitely do something like this. In fact, ZeroBrane Studio already includes the API description for Love2d: https://github.com/pkulchenko/ZeroBrane ... love2d.lua; it's not a standalone module, but a structure that ZBS uses to provide auto-complete for love2d API. "lua-inspect" is not involved in this case.
Desty
Prole
Posts: 4
Joined: Sat Oct 27, 2012 7:26 pm
Location: Ireland

Re: Lua auto-complete?

Post by Desty »

paulclinger wrote:Yes, you can definitely do something like this. In fact, ZeroBrane Studio already includes the API description for Love2d: https://github.com/pkulchenko/ZeroBrane ... love2d.lua; it's not a standalone module, but a structure that ZBS uses to provide auto-complete for love2d API. "lua-inspect" is not involved in this case.
Ahh, excellent. Did you construct that all by hand?
Maybe I can steal this and modify it slightly to walk the structure and produce one which looks like the implicit love module.
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Lua auto-complete?

Post by paulclinger »

Desty wrote:Ahh, excellent. Did you construct that all by hand?
Maybe I can steal this and modify it slightly to walk the structure and produce one which looks like the implicit love module.
Sure; I used a file that someone put together (from this thread: viewtopic.php?f=3&t=1796&start=30). The Lua script I wrote to convert is at the bottom of the love2d.lua file.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 4 guests