I'm trying to figure out how I could write an autocompletion algorithm for Lua, but since as with many scripting languages it lacks a static type system I think I need background compilation, but during background compilation it's easy to hit the halting problem so I was wondering if anyone has solved this sort of thing before, and what are the standard strategies for solving compilation and halting?
Asked
Active
Viewed 342 times
0
-
What do you mean, "hit the halting problem"? I suspect you mean something other than what "the halting problem" normally refers to in computing... – chaos Feb 25 '09 at 14:45
-
The halting problem is that a program can't be evaluated, in that sense it's the same, the compiler = execution with scripting so it's the same problem, even VS's background compilation can be halted when writting broken template code in C++ – Robert Gould Feb 25 '09 at 14:53
-
I agree with chaos - that doesn't sound the 'halting problem' at all. That sounds like a hang in the compiler. – Douglas Leeder Feb 25 '09 at 14:56
-
Ok maybe it's not halting related, directly, but the question still stands. How do you do background compilation for scripting when evaluation might continue for ever – Robert Gould Feb 25 '09 at 15:15
-
Evaluation of what? I may be being slow today, but I really don't understand what your problem is. I'm awful tempted to vote to close on the principle that I don't see a real question. – David Thornley Feb 25 '09 at 17:05
2 Answers
1
Autocompletion based on static text analysis sounds more reasonable than trying to compile in the background. Most text editors that provide autocomplete use this method, although it isn't as accurate.
To do so, you can parse the document looking for names and recording the scope they belong to. As the point moves through the document, your autocomplete notes the scope it is currently in and provides the names that should be available at that point.
As LUA is global scope by default, you may end up with a fairly polluted namespace if your programmers aren't using the "local" keyword to narrow scopes.

Godeke
- 16,131
- 4
- 62
- 86
1
You can
- actually execute the code to see what kind of object is represented by a particular variable, and cut the execution in the middle if it takes too long
- guess what type would the actual variable have, if Lua had types. This means you'd have to create a type system, which is a nontrivial task (you have to be enough restrictive to allow reasoning about the object model, and enough permissive for enough Lua programs actually conform to your model). However, all the shiny new javascript engines try to do this, AFAIK, so you could look there for pointers.
- just guess from the syntax. For example, emacs completion, which only looks for the same prefixes, works like charm in cases where other IDEs usually fail (C++ templates)

jpalecek
- 47,058
- 7
- 102
- 144