lua-users home
lua-l archive

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


Hi,

That's a tough one - how would you handle


remote_cos = handle.math.cos
res = remote_cos(3.1)

or

table_I_want_transferred_in_its_entirety_now = handle.a_table

Can you work out a user's intentions without extra syntax?

You could obviously have some kind of evaluate function:

res = rpc.evaluate(handle.sometable.entry)

but I guess you're trying to avoid that because you didn't mention it? 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.

Cheers,
Geoff

On 4/06/2009, at 4:45 AM, James Snyder wrote:

Hi -

I've been working on adding some features to Russell Smith's Lua-RPC (http://q12.org/lua/index.html), which I've started putting up on GitHub here (functional, but not yet at a release stage: http://github.com/jsnyder/luarpc/) . It works by having a server listen for incoming requests for function calls. When one comes in it executes it and handles the return of data from the called function back to the client machine. The client side is slightly more interesting, when one successfully connects to a server, one gets a handle userdata, which has an __index metatable. When the table is indexed, a helper userdata is created with a __call metatable. If this helper is called, the function name is transmitted to the remote Lua state and pcalled with a custom error handler. Depending on how things complete; results or error handling information are passed back to the client that initiated the call.

This works fairly well, but I would like to extend it so that in addition to calls to global functions, one could also call functions registered on tables, as well as just index remote variables or table entries to be able to inspect the remote state without having to send a function over to do that.

As it stands, one can do things like:
handle = rpc.connect()
res = handle.tostring(3.15)

The number 3.15 goes out to the server, the server does the tostring, and the resulting string is passed back to the client on the stack.

Now to the question:
I'd like to be able to do things like:
res = handle.math.cos(3.1)

or:

res = handle.sometable.someentry

and have the former perform the operation on the remote machine, with a result returned, or the latter give me what was in someentry on the remote machine. What I'm unsure of however is how to know whether the sequence will end with gettable or call before returning. Any suggestions on how to structure that to work for either situation? It would be quite neat to be able to essentially work with a remote Lua environment just by prepending the handle.

Thanks in advance :-)


--
James Snyder
Biomedical Engineering
Northwestern University
jbsnyder@fanplastic.org
http://fanplastic.org/key.txt
ph: (847) 448-0386