lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Apr 26, 2004 at 08:08:15PM +0200, Philippe Lhoste wrote:
> Scott wrote:
> One thing your code does not consider that can be very helpfull is the use
> of the ':' seperator in addition to '.'  I wrote something very similar for
> the console of our game and I don't remember there being any trick to
> getting ':' working.  Just check for ':' anywhere you would also look for
> '.'
> 
> I don't agree, at least in the scope of this snippet.
> When you have myFileHandle:o you cannot know what kind of object is 
> myFileHandle, so you cannot provide efficient autocompletion (ie. only the 
> set of methods applicable to this object).
> Or if you can, I would be interested to know how.
> 

I went back and looked at my code.  As you suggested, my code does not
handle the case where the object preceeding a ':' is a userdata.  But it
does handle the case where the object preceeding a ':' is a table, which
is what I have used it for.  

--[[ I need to alias for this simple test, since my code only autocompletes
one level ]]
stdErrAlias = io.stderr

--[[ getMatchingCommands is my autocompleter method. It takes a string and
returns a table of matching Lua object names]]
matches = getMatchingCommands( "stdErrAli" )
for k,v in pairs( matches ) do print( tostring(k), tostring(v) ) end

1   stdErrAlias  -- finds the correct name.


matches = getMatchingCommands( "stdErrAlias:" )
for k,v in pairs( matches ) do print( tostring(k), tostring(v) ) end

--[[ nothing is printed.  As you suggested, my implementation punts when it
comes across a userdata.]]

However...

foo = {}
function foo:bar() end
function foo:car() end
function foo:dar() end
foo.ear = "hi"

for k,v in pairs( getMatchingCommands("foo:") ) do print( tostring(k), tostring(v) ) end

1   foo:car -- all three methods and one member are found.
2   foo:dar
3   foo:ear
4   foo:bar

Of course, the autocompletion isn't always sensical Lua code, but that
wasn't my intent.  I just wanted to help speed up typing and provide an
aid to remembering all the methods implemented in each table.  I let the Lua
parser worry about whether the code works or not and provide a command
history on the up arrow for when the code is wrong. :)

scott

-- 
------------------------------------------------------------------------
scott jacobs                                   scott+lua@escherichia.net
------------------------------------------------------------------------