lua-users home
lua-l archive

RE: Functions prototypes and real #defines

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


You can forward declare functions only in the limited sense that you can
declare an upvalue and then define it later:
-- Declare handler
local handler
function func( event )
 handler( event )
end
-- Define handler
handler = function( event )
 ...
end
One way of handling #defines (or any other C preprocessor feature) is to
run a C preprocessor over your lua code.
-Kevin
> 
> Hi.
> 
> It's possible to define functions prototypes in Lua?
> 
> In the following example, I must have defined the
> function "e1_func" before attrib to e1.func, or there
> is some way of just declare a prototype, and later or
> in another module define it:
> 
> function e1_func()
> 	...
> end
> 
> e1.func = e1_func
> 
> 
> By the way, is there some way of creating "real
> #defines" in Lua?
> 
> If I do something like this:
> 
> ENEMY1 = 1
> ENEMY2 = 2
> ...
> ENEMY100 = 100
> 
> 
> if enemy.type == ENEMY1 then
> ...
> end
> 
> I created 100 variables, when I just needed the value
> of the constant.
> 
> In C, it could be:
> 
> #define ENEMY1 1
> #define ENEMY2 2
> ...
> #define ENEMY100 100
> 
> 
> if( enemy.type == ENEMY1){
> ...
> }
> 
> better, could use a enum.
> 
> 
> ______________________________________________________________________
> 
> Yahoo! Messenger - Fale com seus amigos online. Instale agora! 
> http://br.download.yahoo.com/messenger/
> 

AltStyle によって変換されたページ (->オリジナル) /