lua-users home
lua-l archive

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

Actually, a syntax modifier could easily automatically make all your "usual globals" declared as locals.

It could even change references to string.* etc. to be locals. Without you needing to do this explicitly.

	print( string.find )


	local print= print		-- prefix code automatically added to each chunk
	local string= string
	local string_find= string.find

	print( string_find )		-- modified of the actual source above

Would you rather have it this way?


David Given kirjoitti 15.9.2008 kello 19:04:

Tony Finch wrote:
On Fri, 12 Sep 2008, David Given wrote:
- Lua doesn't have a preprocessor. My app was made up of multiple source files, and most of the time I wanted the same common header at the top of each source file (importing C functions, mostly). Many's the time I
wished for #include.

It's a dynamic language, so you achieve something like that by calling a
global function which sets up the namespace at run time.

Yes, except that these are all local variables, which means they're
lexical and don't exist in a namespace.

All my Lua files tend to start with the same boilerplate containing
lists of:

local string_find = string.find
local table_insert = table.insert
local print = print

...etc. It would be really nice to be able to common this somehow.

David Given