不同lua状态之间的lua_xmove [英] lua_xmove between different lua states

查看:172
本文介绍了不同lua状态之间的lua_xmove的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据lua 5.1手册,lua_xmove在属于同一Lua状态的不同线程的堆栈之间移动值.但是,我不小心碰巧用它在Lua的不同州之间移动了值,而且看起来还不错!是否还有其他API可以将值从一个Lua状态移动到另一个Lua状态(在5.1中),或者可以使用lua_xmove吗?

According to the lua 5.1 manual, lua_xmove moves values between stacks of different threads belonging to the same Lua state. But, I accidentally happened to use it to move values across different Lua states and it seemed to work fine! Is there any other API to move values from one Lua state to another (in 5.1), or can lua_xmove be used?

推荐答案

Lua在全局状态下存储垃圾收集数据.因此,如果跨状态移动GC或字符串对象,则可能会混淆垃圾回收器并创建悬挂的引用.

Lua stores garbage collection data in the global state. So, if you move GC or string objects across states, you can potentially confuse the garbage collector and create dangling references.

因此,尽管它看起来很有效,但以后很可能会引起问题.

So, while it might look like it works, it could just as easily cause problems later on.

有关参考,请参见此邮件列表线程开发人员在这里讨论这个确切的问题.

For reference, see this mailing list thread where developers discuss this exact issue.

请注意, lua_xmove 确实会检查全局状态是相同的:

Note that lua_xmove does check that the global states are the same:

api_check(from, G(from) == G(to));

这篇关于不同lua状态之间的lua_xmove的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆