lua-users home
lua-l archive

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


Kevin Martin wrote:
> My best thought is that a relocal command that creates local
> variables only if they aren't local in the same scope level.
>
> Is this a good idea, or am I just looking at the problem the wrong way?  How do other people deal with forward declarations?

I think the current behaviour is nice, because it encourages defining
functions where you declare them and naturally leads to script files
where often needed "helper" functions are near the start, and high
level/exported functions (that depend on lots of things you just
declared) near the end of the file.
IMHO this is clearly preferable over the C-way, where you have
function definitions (and declarations) in completely random order
(generally speaking).
--> It's nice that Lua makes you avoid forward declarations, but still
makes them possible.

I do this the same way Roberto advised (I think): No forward
declaration if it can be avoided (... without rewriting the whole
chunk).
Also, for me its easier (mainly because of N++ syntax highlighting) to
distinguish
    local <name> = [...]
from
    <name> = [...]
then
    local function <name>[...]
from
    function <name>[...]
thus I use the assignment syntax for function definitions:
    local f = function(...) [...]
And when I see
    f = function(...)
I know immediately that it was forward declared (because I don't use globals).

--Wolfgang