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.
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Lua auto-complete?

Post by OmarShehata »

So I've been slowly getting the hang of metatables and whatnot in order to code in OOP.

The one thing I can't seem to get working is that, assume I got my "class" set up and made an instance of it and set it as my metatable and everything. Now I want it so that, when I type:

MyObject.

It shows me the functions and variables inside the "class" that I can access, otherwise things would get pretty messy.

I'm using Sublime Text 2 as my code editor. Any idea how to get this working?

EDIT: If anyone has this working in any IDE, please let me know. I'm willing to switch if necessary.

Thanks!
Last edited by OmarShehata on Thu Jun 14, 2012 11:56 am, edited 3 times in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: OOP in Lua?

Post by kikito »

Your post has little to do with OOP in Lua. I suggest you rename it to something like "How do I get autocomplete for Lua in Sublimetext?" (Which by the way, I have no idea how to do)
Last edited by kikito on Thu Jun 14, 2012 2:21 pm, edited 1 time in total.
When I write def I mean function.
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: OOP in Lua?

Post by OmarShehata »

kikito wrote:Your post has little to do with OOP in Lua. I suggest you modify it to something like "How do I get autocomplete for Lua in Sublimetext?" (Which by the way, I have no idea how to do)
Thanks for the heads up, changed it.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Lua auto-complete?

Post by Xgoff »

you can't get a whole lot of information about lua code without actually executing it (dynamic language and all that). __index can do anything which definitely does not help

in fact i'm not sure even luainspect can do this. not to say this is impossible but it's not trivial.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Lua auto-complete?

Post by Roland_Yonaba »

To second Xgoff, I don't know if actually, there is any IDE featuring this.
Not saying that this is not doable, but maybe nobody thought at it...
But, I don't think this is really necessary.
As you are the one who defines your methods and attributes inside a class, you hopefully won't make confusions.
You just have to be organized, and clearly comment your code.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Lua auto-complete?

Post by kikito »

If you use Notepad++, there is a plugin that autocompletes the LÖVE functions as you type.

It's an xml file, so it shouldn't be very difficult to update it with more functions, if you need to.

What I haven't seen yet is an editor that "really loads the possible members" as you type. Lua makes this pretty much impossible in some cases. You could use __index when it points to a table, for example, but not not when it points to a function.
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Lua auto-complete?

Post by bartbes »

I think I have a lua extension for vim that supports most completion (it basically interprets the file), but as kikito said, it's impossible to get all members of a table with an __index metamethod. Also, I haven't really used it either, it's really slow.
kclanc
Citizen
Posts: 89
Joined: Sun Jan 29, 2012 6:39 pm

Re: Lua auto-complete?

Post by kclanc »

I do not know of any IDEs that do this (apparently bartbes's plugin does, though). Implementing this feature in a way that is class system neutral would be pretty dang hard. However, implementing it for a particular class system would be doable. One reason that this is difficult to do is that, because lua is dynamic, a function's arguments are not annotated with types. So if you passed your object as an argument to a function, how would the IDE know which class to retrieve the methods of? Of course, there are ways around this: type assertions and annotations embedded in comments come to mind. Even without those, you could still provide intellisense for indices into self; that would likely prove useful for class systems with mixins.

I was trying to work class-system-aware intellisense into love studio a few months back, but haven't worked on it in awhile due to school.
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: Lua auto-complete?

Post by OmarShehata »

So it looks like due to Lua's nature, this is pretty much impossible unless you custom-tailor your own plugin to work for your specific code structure, but I'm not sure if that'd be worth the time and effort. But hey, if everyone else can live without it, I guess I can too.

I was considering attempting to make my own version of Lua with brackets for everything, that would first compile to Lua, removing the brackets and placing indents where appropriate then compiling that Lua file. How hard/practical would that be? Perhaps someone could make a stricter version of Lua.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Lua auto-complete?

Post by kikito »

OmarShehata wrote:I was considering attempting to make my own version of Lua with brackets for everything, that would first compile to Lua, removing the brackets and placing indents where appropriate then compiling that Lua file. How hard/practical would that be? Perhaps someone could make a stricter version of Lua.
That sounds a lot like moonscript (it uses spacing instead of brackets, like Python).
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests