lobject.h
Userdata
/*
** Light userdata should be a variant of userdata, but for compatibility
** reasons they are also different types.
*/
#define LUA_VLIGHTUSERDATA makevariant(LUA_TLIGHTUSERDATA, 0)
#define LUA_VUSERDATA makevariant(LUA_TUSERDATA, 0)
LUA_TLIGHTUSERDATA:轻量用户数据是一个简单的指针,不受 Lua 垃圾收集器管理,适合用于传递简单的指针。
LUA_TUSERDATA:完整用户数据是一个包含任意数据块的对象,受 Lua 垃圾收集器管理,适合用于需要 Lua 管理内存的复杂数据结构。
/* Ensures that addresses after this type are always fully aligned. */
typedef union UValue {
TValue uv;
LUAI_MAXALIGN; /* ensures maximum alignment for udata bytes */
} UValue;
uv是指针所指向值,LUAI_MAXALIGN用于确保数据对其
#define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l
/*
** Header for userdata with user values;
** memory area follows the end of this structure.
*/
typedef struct Udata {
CommonHeader;
unsigned short nuvalue;