LUA源码中涉及到的数据结构

typedef struct UpVal 
{
 {
  GCObject *next; 
  unsigned char tt; 
  unsigned char marked;
 }
 TValue *v;  
 union 
 {
 TValue value; 
  struct 
  {  
   struct UpVal *prev;
   struct UpVal *next;
  }l;
 } u;
} UpVal;

typedef union Value 
{
 GCObject *gc;    
 void *p;         
 int b;           
 lua_CFunction f; 
}Value;

typedef struct lua_TValue 
{
 TValuefields;
}TValue;

#define TValuefields Value value_; int tt_

#define TValuefields union { struct { int tt__; Value v__; } i; double d__; } u //大

typedef struct lua_TValue 
{
 Value Value;
 int tt_;
}TValue;

typedef struct lua_TValue 
{
union
 { 
  struct 
   { 
   int tt__; 
   Value v__; 
   } i; 
  double d__; 
 } u;
}TValue;

typedef union TKey 
{
 struct 
 {
  TValuefields;
  struct Node *next;  
 } nk;
 TValue tvk;
} TKey;

typedef struct Node 
{
 TValue i_val;
 TKey i_key;
} Node;

ypedef struct Table 
{
 {
  GCObject *next; 
  unsigned char tt; 
  unsigned char marked;
 }
 unsigned char flags;  
 unsigned char lsizenode;  
 struct Table *metatable;
 TValue *array;  
 Node *node;
 Node *lastfree;  
 GCObject *gclist;
 int sizearray;  
} Table;

typedef union Udata 
{
 struct 
 {
  {
   GCObject *next; 
   unsigned char tt;
   unsigned char marked;
  }
  struct Table *metatable;
  struct Table *env;
  size_t len;  
 }uv;
} Udata;

typedef struct CClosure 
{
 {
  GCObject *next; 
  unsigned char tt; 
  unsigned char marked;
  unsigned char nupvalues; 
  GCObject *gclist;
 }
 lua_CFunction f;
 TValue upvalue[1];
} CClosure;

typedef struct LocVar 
{
 TString *varname;
 int startpc;  
 int endpc;    
} LocVar;

typedef struct Upvaldesc 
{
 TString *name;  
 unsigned char instack;  
 unsigned char idx;  
} Upvaldesc;

typedef struct Proto 
{
 {
  GCObject *next; 
  unsigned char tt;
  unsigned char marked;
 }
 TValue *k;  
 unsigned int *code;
 struct Proto **p;  
 int *lineinfo;  
 LocVar *locvars;  
 Upvaldesc *upvalues;  
 union Closure *cache;  
 TString  *source;  
 int sizeupvalues;  
 int sizek;  
 int sizecode;
 int sizelineinfo;
 int sizep;  
 int sizelocvars;
 int linedefined;
 int lastlinedefined;
 GCObject *gclist;
 unsigned char numparams;  
 unsigned char is_vararg;
 unsigned char maxstacksize;  
} Proto;

typedef struct LClosure 
{
 {
  GCObject *next; 
  unsigned char tt; 
  unsigned char marked;
  unsigned char nupvalues; 
  GCObject *gclist;
 }
 unsigned char nupvalues;
 struct Proto *p;
 UpVal *upvals[1];  
} LClosure;


typedef union Closure 
{
 struct CClosure c;
 struct LClosure l;
} Closure;

typedef struct UpVal 
{
 {
  GCObject *next; 
  unsigned char tt; 
  unsigned char marked;
 }
 TValue *v;  
 union 
 {
 TValue value; 
  struct 
  {  
   struct UpVal *prev;
   struct UpVal *next;
  }l;
 } u;
} UpVal;

typedef union GCObject 
{
 typedef struct GCheader 
 {
  GCObject *next; 
  unsigned char tt; 
  unsigned char marked;
 } gch;  
 union TString ts;
 union Udata u;
 union Closure cl;
 struct Table h;
 struct Proto p;
 struct UpVal uv;
 struct lua_State th;  
}GCObject;

typedef union TString 
{
 struct 
 {
  GCObject *next;
  unsigned char  tt; 
  unsigned char  marked;
  unsigned char  extra;
  unsigned int hash;
  size_t len;
 } tsv;
}TString;

typedef struct CallInfo 
{
 TValue * func;  
 TValue * top;  
 struct CallInfo *previous; 
 struct CallInfo *next; 
 short nresults;  
 unsigned char callstatus;
 int extra;
 union 
 {
  struct 
  {  
   TValue * base;  
   const unsigned int *savedpc;
  } l;
  struct 
  {  
   int ctx;  
   lua_CFunction k;  
   int old_errfunc;
   unsigned char old_allowhook;
   unsigned char status;
  } c;
 } u;
} CallInfo;

typedef struct stringtable 
{
 GCObject **hash;
 unsigned int nuse;  
 int size;
} stringtable;

typedef struct Mbuffer 
{
 char *buffer;
 size_t n;
 size_t buffsize;
} Mbuffer;

struct lua_longjmp 
{
 struct lua_longjmp *previous;
 int b;
 volatile int status;  
};

typedef struct lua_State 
{
 GCObject *next; 
 unsigned char tt; 
 unsigned char marked;
 unsigned char status;
 TValue * top;  
 global_State *l_G;
 CallInfo *ci;  
 const unsigned int *oldpc;  
 TValue * stack_last;  
 TValue * stack;  
 int stacksize;
 unsigned short nny;  
 unsigned short nCcalls;  
 unsigned char hookmask;
 unsigned char allowhook;
 int basehookcount;
 int hookcount;
 lua_Hook hook;
 GCObject *openupval;  
 GCObject *gclist;
 struct lua_longjmp *errorJmp;  
 int errfunc;  
 struct CallInfo base_ci;  
}lua_State;

typedef struct global_State 
{
 lua_Alloc frealloc;  
 void      *ud;         
 size_t totalbytes;  
 int GCdebt;  
 size_t GCmemtrav;  
 size_t GCestimate;  
 struct stringtable strt;  
 TValue l_registry;
 unsigned int seed;  
 unsigned char currentwhite;
 unsigned char gcstate;  
 unsigned char gckind;  
 unsigned char gcrunning;  
 int sweepstrgc;  
 GCObject *allgc;  
 GCObject *finobj;  
 GCObject **sweepgc;  
 GCObject **sweepfin;  
 GCObject *gray;  
 GCObject *grayagain;  
 GCObject *weak;  
 GCObject *ephemeron;  
 GCObject *allweak;  
 GCObject *tobefnz;  
 struct UpVal uvhead;  
 struct Mbuffer buff;  
 int gcpause;  
 int gcmajorinc;  
 int gcstepmul;  
 lua_CFunction panic;  
 struct lua_State *mainthread;
 const double *version;  
 TString *memerrmsg;     
 TString *tmname[17];  
 struct Table *mt[9];  
}global_State;
PS:此图画的真的很辛苦希望转载请说明出处.上传的时候故意没有加水印哦 害羞
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值