Create new empty user data from pure Lua

I think I saw somewhere a native function in Lua that can return new user data. He exists? Is it possible to create user data from a regular Lua script?

+4
source share
2 answers

Maybe you think about newproxy

From: http://lua-users.org/wiki/HiddenFeatures

newproxyis an unsupported and undocumented function in the Lua database library. From Lua code, you can use a function setmetatableon table type objects. The function newproxybypasses the limitation by creating zero user data and setting either a new, empty metataber on it or using another metatable newproxyexample. Then we can change the meta from Lua. This is the only way to create a proxy object from Lua that honors certain metamethods, such as __len.

It is also useful for metathemes __gclike hacking a callback when an instance newproxybecomes free.

This feature was present in Lua 5.1, but removed in 5.2. In Lua 5.2, metamethods __gccan be installed on tables with zero size, so the main impulse for newproxygone.

+8

, Lua.

userdata, C Lua.... userdata Lua, API C. , -.

luaVM - C/++, userdata Lua, . UD Lua.

+2

Source: https://habr.com/ru/post/1540100/


All Articles