[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Object or table?
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Tue, 23 Aug 2011 15:33:11 +0200
2011/8/23 Stefan Reich <stefan.reich.maker.of.eye@googlemail.com>:
> 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?
If you want your messaging system to be transparent, any mutable value
should be considered an object and be referenced rather than copied.
Otherwise you may break some semantics from the language. You can
however provide some mechanism to explicitly perform a copy (or move)
of objects between your sandboxes. Then passing a reference to a
remote object (ie. an object made explictly remote by a move
operation) in a remote call could be resolved in the remote sandbox as
a local reference, which should solve the issue.