lua-users home
lua-l archive

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


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
end

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..'".' )
end
----- 8< --- another module ---- 8< ----
MyClass:print_msg( MyClass.HELLO_MSG )

...or something to that effect.

Hope that helps,

Cheers,

	Pedro.