lua-users home
lua-l archive

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

I provide effectively a "API" to others writing lua scripts in my app and when I want to provide constants, I add a new entry in my "constants" table, named "id".

Thus, say I want a constant "defaultSize" or "redColor" and so on, they become:


and so on.. it's clean, all in a table, and by having them in the lua code start with id lets the casual obvserver see they are predefined constants...


On Tuesday, October 7, 2003, at 08:20 AM, Pedro Miller Rabinovitch wrote:

On Tuesday 07 October 2003 06:53, Brett Bibby wrote:
Does lua support preprocessor constants?  I'm guessing no by the
archived notes I did see. As a lua newbie, is there a technical reason
it's not supported?

I've never really felt the need for them. When I need that kind of behaviour
file-wise, I use something like

local MY_CONSTANT = 10
-- ...
for i = 1, MY_CONSTANT do
 --..., etc

If I need module-wide (and exported) constants, I place them inside my "class"
table, thus:

MyClass = {}

MyClass.HELLO_MSG = "Hello!\n"

function MyClass:print_msg( message )
	print( 'MyClass says, "'..message..'".' )
----- 8< --- another module ---- 8< ----
MyClass:print_msg( MyClass.HELLO_MSG )

...or something to that effect.

Hope that helps,



Ando Sonenblick
SpriTec Software