table deep copy in C/CPP

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: table deep copy in C/CPP

Pan, Shi Zhu
On Sun, Mar 21, 2010 at 7:41 PM, Asko Kauppi <[hidden email]> wrote:
>
> I think it did not copy the environment, though that could actually be
> implemented if needed.
>
> It would copy the function given as upvalue. It only stops when there's a
> recursion (i.e. it cannot copy a function which has itself as upvalue,
> though even this could possibly be implemented, if needed).
>

What I want is to serialize a function and transmit it in a network
socket, then unserialize it in another process (the process runs on
another computer).

does lua lanes copied function support this?
Reply | Threaded
Open this post in threaded view
|

Re: table deep copy in C/CPP

Patrick Donnelly
On Sun, Mar 21, 2010 at 8:44 PM, Pan Shi Zhu <[hidden email]> wrote:

> On Sun, Mar 21, 2010 at 7:41 PM, Asko Kauppi <[hidden email]> wrote:
>>
>> I think it did not copy the environment, though that could actually be
>> implemented if needed.
>>
>> It would copy the function given as upvalue. It only stops when there's a
>> recursion (i.e. it cannot copy a function which has itself as upvalue,
>> though even this could possibly be implemented, if needed).
>>
>
> What I want is to serialize a function and transmit it in a network
> socket, then unserialize it in another process (the process runs on
> another computer).
>
> does lua lanes copied function support this?

Here's a Lua serialization library I wrote for an IRC bot. It can
serialize anything but unknown C functions, all userdata, and
coroutines. (It also uses the debug.upvalue & debug.upvaluejoin from
Lua 5.2 but this is backwards compatible.)

http://www.batbytes.com/serialize.lua


--
- Patrick Donnelly
Reply | Threaded
Open this post in threaded view
|

Re: table deep copy in C/CPP

Asko Kauppi
In reply to this post by Pan, Shi Zhu

Pan Shi Zhu kirjoitti 22.3.2010 kello 2:44:

> On Sun, Mar 21, 2010 at 7:41 PM, Asko Kauppi <[hidden email]>  
> wrote:
>>
>> I think it did not copy the environment, though that could actually  
>> be
>> implemented if needed.
>>
>> It would copy the function given as upvalue. It only stops when  
>> there's a
>> recursion (i.e. it cannot copy a function which has itself as  
>> upvalue,
>> though even this could possibly be implemented, if needed).
>>
>
> What I want is to serialize a function and transmit it in a network
> socket, then unserialize it in another process (the process runs on
> another computer).
>
> does lua lanes copied function support this?

Absolutely.

Though Lanes does not do the transfer for you, and the architectures  
of the two machines need to match.

- asko

ps. "Absolutely" above naturally implies it's a Lua function. A C  
function usable in Lua can hardly be serialized.
12