LUA_NEWUSERDATA(3) | Library Functions Manual | LUA_NEWUSERDATA(3) |
lua_newuserdata
—
allocates a new block of memory with the given size,
function indicator [-0, +1, m]
#include
<lua.h>
void *
lua_newuserdata
(lua_State
*L, size_t
size);
lua_newuserdata
()
allocates a new block of memory with the given size, pushes onto the stack a
new full userdata with the block address, and returns this address.
Userdata represent C values in Lua. A full userdata represents a block of memory. It is an object (like a table): you must create it, it can have its own metatable, and you can detect when it is being collected. A full userdata is only equal to itself (under raw equality).
When Lua collects a full userdata with a gc metamethod, Lua calls the metamethod and marks the userdata as finalized. When this userdata is collected again then Lua frees its corresponding memory.
Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, Lua 5.1 Reference Manual.
The lua_newuserdata
() manual page is based
on Lua Reference Manual 5.1 and was created by Sergey Bronnikov.
July 15, 2022 | Debian |