当前位置:网站首页>Lua tvalue structure

Lua tvalue structure

2022-06-12 13:57:00 HyperCall

LUA TValue

// Its form is as follows :
typedef struct TValue {
    
  Value value_;	//raw value
  lu_byte tt_;	//raw type tag
} TValue;

// Its Value by LUA Of the supported basic types union form 
typedef union Value {
    
  struct GCObject *gc;
  void *p;
  lua_CFunction f;
  lua_Integer i;
  lua_Number n;
} Value;

// lu_byte tt_  namely  unsigned char tt_  For variable types 
 therefore ttisinteger(o)  Equivalent to  o->tt_ == 3 ? true : false

union The specific meaning of each item in the structure is :

Variable explain
GCObject gch For recycling It is mainly used to connect the cross reference relationship of garbage collection objects
void *p by c Pointer passed in , from c Distribute and release
lua_CFunction f Express C Export to lua Function pointer of ,typedef int (*lua_CFunction) (lua_State *L);
lua_Integer i Represents an integer type ,typedef long long lua_Integer;
lua_Number n Represents a double-precision floating point type ,typedef double lua_Number;

I found one on the Internet TValue See the following figure for the structure :
 Icon
There have been some visible changes in the graphics and code , so lua 5.3 The version has some changes compared with the diagram structure , For example, the original use of int Type storage bool It's worth it b, Store all numeric types of double n Split to store integers lua_Integer Of i And storing double precision floating-point numbers n
among GCObject gch Structure , as follows :

typedef struct GCObject {
    
	struct GCObject *next;
	unsigned char tt;
	unsigned char marked;
} GCObject;

next Point to the next linked list structure ,tt Indicates the type ,marked Is a sign of garbage collection , Specifically LUA 5.3 For the garbage collection mechanism, see :LUA 5.3 Garbage collection mechanism .( Important but not urgent )

原网站

版权声明
本文为[HyperCall]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010514053500.html