1. 程式人生 > >lua源碼:Tvalue

lua源碼:Tvalue

string 原型 不可 對象 回收 user all lean 源碼

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 */

};

lua源碼:Tvalue