[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Extending Lua-RPC: questions about handling index and call events
- From: James Snyder <jbsnyder@...>
- Date: Wed, 3 Jun 2009 11:45:58 -0500
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)
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 :-)
ph: (847) 448-0386
Description: This is a digitally signed message part