lua-users home
lua-l archive

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


Maybe you could make use of the `__metatable' meta field in objects' metatable.

just set a special value to `__metatable', so that you may tell a object from a table by the returned value of 'getmetatable' function.

Do I get your questioncorrectly?

于 2011-8-23 21:24, Stefan Reich 写道:
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