[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Extending Lua-RPC: questions about handling index and call events
- From: Geoff Leyland <geoff_leyland@...>
- Date: Thu, 4 Jun 2009 13:20:52 +1200
On 4/06/2009, at 12:25 PM, James Snyder wrote:
Would lazy evaluation work? You could not do anything until the
object is used by a __call, __tostring, __add or some other
metamethod. There would be the usual problem with comparison
operators, but it would work some of the time I think.
That works for a fair number of things so long as there's a
metamethod that can be hooked prior to an operation.
It does get weird with something like:
value_from_server = handle.some_value
value_from_server + local_value
or even things like:
value_from_server + handle.some_other_value
These would both work wouldn't they? Your helper's __add would get
its (and the other operand's, if it was also a helper) value from the
server and do the job locally. (Which is what I think you wrote
next). I don't see a problem with that - am I missing something? You
*could* build a syntax tree and serialise that and send it to the
server, but that'd be probably more complication than is necessary.
To me it would make the most sense to, when possible, pull both to
the local environment, and then perform the local operation as it
would with that type. I wonder if that could be cleanly generalized
somehow? It would be nice to be able to do things like call
math.cos(handle.some_remote_value) without having to explicitly copy
it from the remote to the local state. For things like this,
That should be possible, right? You're serialising the call anyway,
so if you can just serialise the helper too, it should be possible to
handle it on the remote machine?
It doesn't have to perfectly handle every situation. My main goals
are to make it easy to execute functions on a remote session, and to
make it pretty easy to get data from the remote environment for
further local processing.
I think a combination of laziness and offering a "get" as you mention
below would work fine. There'd be some odd corners when you weren't
sure if you needed a get or forgot one, but that wouldn't be too bad
would it?
Perhaps the easiest approach is to do lazy evaluation, where the
helper can handle __call (to call a remote function), __index (to
index deeper into multiple layers of tables), and a method like
"get" or "copy" that would take anything it knows how to serialize
and copy it to the local stack.
Thanks for your comments and thoughts :-)
Any other suggestions? (doing it all from a module without
modifying Lua itself would be best)
Although the goal is completely different, this has a lot in common
with rima's late bound symbolic math stuff - which is far from elegant
or finished at the moment - so I'll look forward to seeing what you
come up with. Rima does have an eval, and it includes the
"connection" (called a scope), so, in your context you'd have
something like:
local a, b = rpc.helper"a, b"
local e = a + b.some_value
local res1 = rpc.eval(e, connection1)
and then you could ask another server/scope the same question
local res2 = rpc.eval(e, connection2)
I doubt that there's any use for that kind of functionality in what
you're doing, but I'm pleasantly surprised that some of the insides
are so similar.
Cheers,
Geoff