lua-users home
lua-l archive

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

I'm thinking about ways to share objects between states, something I've not needed to do before, and have come up with a possible technique:

State L1 has the actual object `obj`
State L2 is given a 'forwarding' object `fwd`

A call in L2, e.g. `fwd:foo("test")`, picks up the name of the method, and it's arguments, than passes them into L1's state, calling the method on `obj`. Results are then returned to L2 as expected, with non-basic Lua types being wrapped in their own forwarding objects.

You could expose plain functions this way too.

So, given that basic outline, a couple of questions:

Q1 : Has anyone ever done this? (Is there already a lib)
Q2 : Is this viable? There's obvious marshalling overhead, and limits on passing types, but if those aren't an issue, does it seem okay? Worst problem may be thread syncing.