lua-users home
lua-l archive

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


Since my last posting about locals I've spent a 
fair amount of time thinking about the issue.  I still
think defaulting to global access is a real problem for
me.  While explaining Lua to some folks for whom I wrote 
a little preprocessor using Lua, I realized that explaining
and supporting the global default model to semi-technical
users is not ideal.

Yesterday, I sat down to work with setting up tag methods 
to at least deliver runtime warnings.  My idea was to make 
it illegal to access globals unless their name started with 
'g' and the second letter was a capital.  As some of you 
probably know, I found that you can't set the get and set
global methods for some built-in types.  Looking at the 
C source code this seems to be prevented by a valid_events
table.  Can I change that table and get access to those
tags?

Anyway, there only seems to be a few other solutions:

1. a method type function definition that defaults to
local.  This could be considered a complication to the
language, but one doesn't have to even explain it to 
users (actually, some of use would stop explaining the
current function...end statement).
	method f(x)
		y=10 -- this is a local
		return x+y
	end
	
2. a preprocessor that modifies source code (I haven't
been able to figure out a complete solution this way).

3. an option to change the access mode when Lua is 
compiled or dynamically from within Lua.

Does anyone agree that this is a problem?  If everyone 
else is happy with global access, please excuse my 
persistance.

To clarify, my basic problem is that default global 
access easily turns typo-bugs into really difficult
ones (that can be extremely execution order dependant).
Creating and accessing globals inadvertantly also makes
writing a long up-time, multi-user, scriptable program 
almost impossible.

Thanks for your consideration,
Russ Webb