lua-users home
lua-l archive

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


Two possibilities, both of which I have actually encountered in my brief
stint using Lua.

1) a, b, foo are local variables in a lua function

function whatever( command, a, b )
  local foo = getMyFoo( ... )
  return eval( command )
end

2) a, b, foo are globals - or there are no variables in the segment. This is
most useful in config file scenarios. Here is why. Let's take this as a
config file:

{
  "key1" = 25,
  "key2" = function (a,b) ... end
...
}

Now, the advantage of this kind of config file (IMHO) is that it does not
pollute the global environment of the corresponding lua_State that it is run
within. Now, you could still pollute the global environment if you wanted
to, but because this code is always accessed (in my system) from C++, C++
never needs to access the global environment. It always just gets an
anonymous reference to the configuration code, like this:

ScriptObject myTable = scriptEngine->eval( myScript );


Does that make sense?

Eric

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Diego Nehab
> Sent: Tuesday, May 22, 2001 2:37 PM
> To: Multiple recipients of list
> Subject: RE: Making vars local by default (completely off topic)
>
>
> Hi,
>
> > Well, that is what I do now as a kind of kludge. But that is not exactly
> > right, unless lua can handle constructs like:
> >
> > return if foo then
> > return a
> > else
> > return b
> > end
> >
> > But surely, if this is a feature that is helpful, we can do better...
>
> And where would the value of foo, a and b come from? What is the kind of
> semantics you are looking for?
>
> Regards,
> Diego.