lua-users home
lua-l archive

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


On Wed, 19 Jul 2023 13:26:01 -0400
Sean Conner <sean@conman.org> wrote:

> The hard
> part will be obtaining the current stack for the coroutine as currently
> there is no API for that, nor for creating the new call stack.  Also
> difficult would be getting the current execution location (IP or PC if you
> know assembly) of the coroutine being duplicated.

Implementing all this would also allow the ability to
serialize/deserialize a coroutine, allowing it to be saved across Lua
instances or persist across reboots, maybe even save in a key/value
store. I have direct use cases for that ability.


>   Another complication are references to tables, userdata and coroutines
> created by the suspended coroutine.  as they are just that---references and
> not copies.  Do they need to be copied as well?  Or are references okay? 
> Tables can be copied but that can get quite expensive, but you are out of
> luck for userdata values as they represent state outside of Lua.

Perhaps, keep userdata - and also tables - as references, but then add
metamethods to define something more sensible. This especially makes
sense in the serialization use case. IE:

{
  __serialize = function( t )
	return 'thing1'
  end,

  __deserialize = function( ref )
        return things.new(ref)
  end
}

-- 
Aaron B. <aaron@zadzmo.org>