[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Need for help
- From: RLake@...
- Date: Wed, 19 Feb 2003 17:17:06 -0500
mnicolet escribió:
> Lots of times, it´s more ´natural´ to get/set the value of a variable
> than to call a function.
Yes. But you can do that.
> The question regarding assignment ´assimetry´ was a claim I posted some
> months ago, and nobody answered.
Sorry. I do sometimes respond to this when it comes up.
> It´s not very orthogonal to use relational operators
> directly, but resort to a method for assignment.
In Lua, assignment is not an operator. I don't find this odd. Maybe
I'm odd. :)
When you say:
a = 3
The previous value of "a" is not consulted. Why should it be? That is
not what assignment means. "=" is not sending a message to the previous
value of a; it is, if you like, sending a message to the global table.
(Or stashing the value in a local variable.)
The only issue here is that you want to use the global name space. I
personally don't think that is good style, although I do find it handy
sometimes in configuration files. In programming, though, I like to keep
my namespaces separate.
Now, if myObj is an object, you can send it any number of assignment
messages like this:
myObj.colour = "red"
myObj.bank_balance = "broke"
Those are cases where assignment is possibly more natural than:
myObj.set_colour("red")
myObj.empty_bank_account()
That is a question of style, I guess. However, I would never
expect the following to work:
myObj = "broke"
Nonetheless, after one of these interminable discussions about
"how do you bind global variables so that they correspond with
C variables", I wrote the following and posted it to the Lua
wiki: <http://lua-users.org/wiki/BoundScalarGlobalsTwo>
Although the code is a little long, it has a lot of comments.
I actually have now used this code in a configuration file, and
it is useful under some very specific circumstances.
Note: you do have to write getter and setter functions. However,
it is very easy to use the same one over and over again, particularly
if the desire is simply to call a C function with the value, or
paste the value into a specific C variable (or structure member).
I hope this counts as a reply.
Rici.