[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Globals vs. Locals
- From: "Vijay Aswadhati" <wyseman@...>
- Date: Fri, 5 Aug 2005 13:21:18 -0700
On Friday, August 05, 2005 10:49 AM, Mark Hambur wrote:
>
> Somewhat unpolished idea that just came to me when thinking about requiring
> globals in scripts to be declared. What if one could write something like:
>
> local for global table, string
>
> This would be equivalent to:
>
> global table, string
> local table, string = table, string
>
> This would encourage people to build scripts that cache global lookups in
> local variables.
C# provides an overloaded feature using the 'using' [1] keyword that is pretty
nice - sugar-wise; with some adaptation a feature like that provides a nice
balance and can solve to a certain degree the global versus local debate.
The usage might vaguely resemble like this:
<vaporware lua code>
-- illustration (1)
using ( table, string, ... )
do
-- any variable access in this block implicitly is
-- limited to those tables and variables specified
-- in the 'using' clause, which as per Mark's suggestion
-- get 'localized'.
end
-- illustration (2)
function foo(...) do
-- something
end
-- somewhere else, foo could be invoked like this:
foo (a1, a2, a3) using (table, string)
-- foo's access to variables are limited to those specified
-- in the using clause. And here the idea is that 'using'
-- clause is optional. If not specified foo has access to
-- pretty much what it can normally.
</vaporware lua code>
I wonder if something like this could be achieved using LHF's proposed
preprocessor and the setenv/getenv functions.
I was just trying out my 'syntax engineering' hat. I will remove it now ;-)
[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcl
rfUsing.asp