lua源码:Tvalue

typedef TValue *StkId; /* 堆栈中的元素 */
typedef struct lua_TValue TValue;

struct lua_TValue {
TValuefields; /* 堆栈中的元素 */
};

// 定义了双精度浮点或者通用类型定义
#define TValuefields
union { struct { Value v__; int tt__; } i; double d__; } u

#define LUA_NUMBER double
typedef LUA_NUMBER lua_Number;
#define numfield lua_Number n; /* 双精度浮点数 */
#define numfield /* no such field; numbers are the entire struct(另外一种定义) */

// Value包括可回收对象和不可回收对象两种类型
// 不可回收对象包括:bool、
union Value {
GCObject *gc; /* collectable objects */
void *p; /* light userdata */
int b; /* booleans */
lua_CFunction f; /* light C functions */
numfield /* 双精度浮点数,实际上可能为空 */
};

/*
** Union of all collectable objects
*/
union GCObject {
GCheader gch; /* common header */
union TString ts; /* 字符串 */
union Udata u; /* 用户自定义数据 */
union Closure cl; /* 函数闭包,其实似乎Proto的一个实例 */
struct Table h; /* 表结构 */
struct Proto p; /* 函数原型,被闭包共享同一个定义 */
struct UpVal uv; /* 闭包所引用的变量 */
struct lua_State th; /* thread */
};

原文地址:https://www.cnblogs.com/losophy/p/10674960.html