lua-users home
lua-l archive

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


On Friday 07 May 2004 18:16, Jose Marin wrote:
> Hi.
>
> It's possible to define functions prototypes in Lua?

If you really need to, you can do the following. It's inefficient though and 
will just keep recursing if you fail to provide the proper definition before 
a call. Better just to reorder your code.

    function e1_func(...) return e1_func(unpack(arg)) end

> By the way, is there some way of creating "real
> #defines" in Lua?

You don't need to. Because Lua strings are pooled, the equality test is just a 
pointer comparison, so the following is a perfectly efficient way to do 
things:

    if enemy.type == "ENEMY1" then ... end

Or if there are lots of choices:

    local switch = { ENEMY1 = function() ... end, ENEMY2 = ... }
    switch[enemy.type]()

-- Jamie Webb