Hi everyone, I have a quick design question - I'm looking for the most
elegant and Lua-like way here.
In Safe Lua, I am now allowing object and function references.
Function and method calls are routed transparently between sandboxes,
like this:
gui = safecomm.invoke{'gui', 'getMasterObject'}
frame = gui:showFrame('frame with label')
label = gui:newLabel('hello')
frame:add(label)
All the colon calls in the example are internally rerouted as messages
(remote calls).
My question arises when tables are sent as method arguments. There are
two cases:
-It's a plain table. Then it should be copied to the receiving sandbox.
-It's an object. Then it should be passed by reference to allow remote calling.
The question is: How do I distinguish a table from an "object"? There
is no clear-cut difference in Lua as far as I understand.
My current solution is to consider a table an object if it contains
only functions. But maybe you just want to pass an array that happens
to contain a function. (Function references are also possible.)
Maybe it would make sense to consider anything with a metatable (even
if the metatable is empty) an object and anything without a metatable
a table.
What do you think?
Greetings,
Stefan