Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the difference between userdata and light userdata?

difference light userdata
0
Posted

What is the difference between userdata and light userdata?

0

lua_newuserdata allocates a block of memory of the given size. The result is called a userdatum, and differs from a block allocated with malloc in two important ways: first, it will be collected by the garbage collector, and second its behaviour can specified by a metatable, just like with Lua tables. There are two metamethods which can only be used with userdata; __len implements the size operator (#) and __gc provides a function which will be called when the userdatum is garbage collected. A good example of this in the standard Lua library are file types, where __gc will close the file handle. The metatable also acts as the unique type of a userdatum. Light userdata, on the other hand, are simple wrappers around a C pointer. They don’t have metatables, and aren’t garbage-collected. Their purpose is to generate unique ‘handles’ which can be cheaply compared for equality. The implementation of a simple array object is discussed in PiL, starting with a simple set of functions and ending

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.