Lua的Pluto库的线程持久性是什么?

问题描述:

在Lua'Pluto图书馆的description中,它表示它保留了函数和线程。Lua的Pluto库的线程持久性是什么?

Can persist any Lua function 
Can persist threads 
Works with any Lua chunkreader/chunkwriter 
Support for "invariant" permanent objects, of all datatypes 

嗯,我无法想象如何保持功能和线程。我可以解释一下这个功能吗?

能坚持任何Lua的功能

这意味着冥王星可以通过坚持它坚持任何的Lua函数的字节码和所有必需upvalues。有关来源,请参阅herehere。当你不使用它时,你可以像往常一样调用函数。请注意,它无法保留在Lua中注册的C函数。

能坚持线程

它仍然存在线程的堆栈和活动记录,所以当你unpersist它,你可以继续在堆栈中执行。代码是here

source code是比较容易遵循和非常评论。

该库确定哪些部分组成函数和/或线程,然后分别存储每个部分。

如果跳过代码,只是阅读注释,这里的两个相关的功能怎么看:

static void persistfunction(PersistInfo *pi) 
{ 
    ... 
    if(cl->c.isC) { 
    /* It's a C function. For now, we aren't going to allow 
    * persistence of C closures, even if the "C proto" is 
    * already in the permanents table. */ 
    lua_pushstring(pi->L, "Attempt to persist a C function"); 
    lua_error(pi->L); 
    } else { /* It's a Lua closure. */ 
    /* Persist prototype */ 
    ... 
    /* Persist upvalue values (not the upvalue objects themselves) */ 
    ... 
    /* Persist function environment */ 
    ... 
    } 
} 

static void persistthread(PersistInfo *pi) 
{ 
    ... 
    /* Persist the stack */ 
    ... 
    /* Now, persist the CallInfo stack. */ 
    ... 
    /* Serialize the state's other parameters, with the exception of upval stuff */ 
    ... 
    /* Finally, record upvalues which need to be reopened */ 
    ... 
} 

所以,你可以看到,函数可以被看作是一个原型的组合物,价值群和环境(一张桌子)。一个线程是两个“堆栈”(我认为是调用堆栈和内存堆栈),状态信息(不包括upvalues),它基本上是什么变量在定义线程时具有哪些值,以及upvalues。

您可以在PiL 27.3.3

中查看更多关于upvalues的信息