lua-users home
lua-l archive

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


> It's possible to define functions prototypes in Lua?

No. Lua is a dynamic language:

http://lua-users.org/wiki/FunctionsTutorial


> 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

You could somehow define a table, which lists the attributes you 

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

No. Well, there is code on the wiki to do preprocessing...

http://lua-users.org/wiki/SimpleLuaPreprocessor

> In C, it could be:
> 
> #define ENEMY1  1
> #define ENEMY2  2
> ...
> #define ENEMY100 100

Now you're thinking C. Lua is not C! You have to accept that these are
two very different types of language. C is a very much a static
language, characterised by strong typing, declarations and compiler time
error reporting. Lua is a dynamic language, which is characterised by
dynamic types, flexibility and less compile time support. The advantage
you get from this are a much more flexible programming environment which
fast to develop, has high level data constructs, is quick to refactor
and far less rigid. The disadvantages are that you get less compile time
support, so potentially more runtime errors, it's slower than native
code.

Try not to think in C, when you're programming dynamic languages like
Lua, Python, Ruby etc or you won't get the best out of them.

Hopefully a lot of this is covered in the tutorial. 

	http://lua-users.org/wiki/LuaTutorial

	http://lua-users.org/wiki/TutorialDirectory

Nick