如何将Lua中创建的空userdata改写成长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计224个文字,预计阅读时间需要1分钟。
我想在Lua中找到一个可以返回新用户数据的本地函数。它存在吗?是否可以从普通的Lua脚本创建自定义用户数据?你可能还会想了解newproxy来自哪里:http://lua-users.org/wiki/HiddenFeatures newproxy
我想我在Lua中看到了一个可以返回新用户数据的本地函数.它存在吗?是否可以从普通的Lua脚本创建自定义用户数据? 你可能会想到newproxy来自:lua-users.org/wiki/HiddenFeatures
newproxyis an unsupported and undocumented function in the Lua base
library. From Lua code, thesetmetatablefunction may only be used
on objects of table type. Thenewproxyfunction circumvents that
limitation by creating a zero-size userdata and setting either a new,
empty metatable on it or using the metatable of anothernewproxy
instance. We are then free to modify the metatable from Lua. This is
the only way to create a proxy object from Lua which honors certain
metamethods, such as__len.
它对于__gc元方法也很有用,因为当newproxy实例变为空闲时,它会获得回调.
此功能在Lua 5.1中出现,但在5.2中已删除.在Lua 5.2中,__ gc元方法可以设置在零大小的表上,因此newproxy的主要推动力消失了.
本文共计224个文字,预计阅读时间需要1分钟。
我想在Lua中找到一个可以返回新用户数据的本地函数。它存在吗?是否可以从普通的Lua脚本创建自定义用户数据?你可能还会想了解newproxy来自哪里:http://lua-users.org/wiki/HiddenFeatures newproxy
我想我在Lua中看到了一个可以返回新用户数据的本地函数.它存在吗?是否可以从普通的Lua脚本创建自定义用户数据? 你可能会想到newproxy来自:lua-users.org/wiki/HiddenFeatures
newproxyis an unsupported and undocumented function in the Lua base
library. From Lua code, thesetmetatablefunction may only be used
on objects of table type. Thenewproxyfunction circumvents that
limitation by creating a zero-size userdata and setting either a new,
empty metatable on it or using the metatable of anothernewproxy
instance. We are then free to modify the metatable from Lua. This is
the only way to create a proxy object from Lua which honors certain
metamethods, such as__len.
它对于__gc元方法也很有用,因为当newproxy实例变为空闲时,它会获得回调.
此功能在Lua 5.1中出现,但在5.2中已删除.在Lua 5.2中,__ gc元方法可以设置在零大小的表上,因此newproxy的主要推动力消失了.

