lua-users home
lua-l archive

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


Thanks you. I will see the link.
I am not talking about lots of globals. I am talkink about some key
variables. I am using lua to configure a ledger system. Most of the
configuration is done calling functions exported from the host.
But some of the scripts must change their behaviour following some ´states´
of the host program, which derive from options the user taken. example is
if Market == "U"
then ...
else if Market == ...
end
Here, Market is a legitimate ´global ´ which is setted every time before lua
execution. Also, it could be
if Market( ) == "U"
then ...
end
But take into account that sometimes, the users must do changes to the
scripts, and they are not very aware of sintactic rules, so the more simple,
the better.
Also, the ´market´ ( this example ) is not an easily accessible member of
the host data structures, ( sometimes, it´s a elaborated ´result´ ). So even
a C function migth require a C global to answer
the query. So, one way or the other, the host code ( which is not simple at
all ) must warrant that all lua globals are ´pushed´ before any lua script
execution.
I am not using variables for lua - host communication, but it would be a lot
more easy if I could
do parts of the configuration simply setting a variable. Imagine: one of the
tasks of lua scripts is
to set the account as a debit or a credit. One function call to say SetDC
( "Debit" ) ?. Luckily, D/C is
only one of the arguments to a more complex function.
Of course, without a binding, to query what the script does to lua globals
is worser than a function call.
That is my point.
Also, I know that assignment in lua is not exactly like other languages. An
object has no value by itself. But that may be ok for the native lua
objects. For more elaborated ( userdata ) this comes to cut the whole idea !
Also, the question of binary operators: they must be the same type. So
c = udata( 4 )
d = 6
if c < d  -- assertion failure
then

what if my metamethod __lt can cope with any type ? it´s very simple to
check the type of the
arguments pushed on the stack.
On the contrary
if c < udata( 6 )
then
involves a big overhead, because there are the call to the constructor (
which in turns calls newuserdata, and setmetatable ) and after that, the
call to the _lt metamethod !!!
It seems a lot more simple, having one of the operands a _lt metamethod, to
pass both arguments
to that function.
Marcelo
----- Original Message -----
From: <RLake@oxfam.org.uk>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Wednesday, February 19, 2003 7:17 PM
Subject: RE: Need for help


> 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.
>
>
>