On 7-Dec-06, at 5:51 PM, Wesley Smith wrote:
> Out of curiosity, has anyone made an attemp to serialize Lua functions
> which could potentially be streamed across a network? What I'm
> looking for is something like this...
>
>
> local streamThisFunction =
> function()
> --params exist elsewhere in script
> function(state, someValues, otherParams)
> end
>
> SendToNetwork(streamThisFunction)
>
> When streamThisFunction is received by another computer, they are able
> to call streamThisFunction() and have it behave as if it were called
> on the original sender's machine.
>
> If no one has done this, what might be invloved in doing it?
>
It's easy if the function has no upvalues. Just use string.dump. If the
function has upvalues, you'd have to serialize them, and they might be
arbitrary objects including userdata.
You might or might not want to worry about the function environment.
I'd be inclined to not worry about it, since the remote machine is
likely to want to run the function in a sandbox anyway.