lua5.3.3源码学习日志(1)--lstate.h

中文记录

可能,会很零碎,看到哪,写到哪。顺便学习markdown,不定期,慢慢更新。

  1. 一些关于gc对象的话,所有的对象objects在lua里面再被释放前,都应该有方法可以访问到。所以,所有的objects总是属于某个(也是唯一一个)列表,通过next字段来链接。

关键字

  • stringtable
 typedef struct stringtable {
        TString **hash;
        int nuse;  /* number of elements */
        int size;
    } stringtable;
  • CallInfo
/*
** Information about a call.
** When a thread yields, 'func' is adjusted to pretend that the
** top function has only the yielded values in its stack; in that
** case, the actual 'func' value is saved in field 'extra'. 
** When a function calls another with a continuation, 'extra' keeps
** the function index so that, in case of errors, the continuation
** function can be called with the correct top.
*/
typedef struct CallInfo {
  StkId func;  /* function index in the stack */
  StkId top;  /* top for this function */
  struct CallInfo *previous, *next;  /* dynamic call link */
  union {
    struct {  /* only for Lua functions */
      StkId base;  /* base for this function */
      const Instruction *savedpc;
    } l;
    struct {  /* only for C functions */
      lua_KFunction k;  /* continuation in case of yields */
      ptrdiff_t old_errfunc;
      lua_KContext ctx;  /* context info. in case of yields */
    } c;
  } u;
  ptrdiff_t extra;
  short nresults;  /* expected number of results from this function */
  lu_byte callstatus;
} CallInfo;
  • 这里我理解为,当调用在某个thread上的时候(yields),func 会被调整成一个顶层函数,在堆栈里拥有着唯一的值。emmmm,还是要去看实现调用。

  • callstatus,类型是 lu_byte(unsigned char),主要用于通过位与确定回调(call)的状态,类型如下:

/*
** Bits in CallInfo status
*/
#define CIST_OAH    (1<<0)  /* original value of 'allowhook' */
#define CIST_LUA    (1<<1)  /* call is running a Lua function */
#define CIST_HOOKED (1<<2)  /* call is running a debug hook */
#define CIST_FRESH  (1<<3)  /* call is running on a fresh invocationof luaV_execute */
#define CIST_YPCALL (1<<4)  /* call is a yieldable protected call */
#define CIST_TAIL   (1<<5)  /* call was tail called */
#define CIST_HOOKYIELD  (1<<6)  /* last hook called yielded */
#define CIST_LEQ    (1<<7)  /* using __lt for __le */
  • 基础设置函数:设置callstatus
/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
#define setoah(st,v)    ((st) = ((st) & ~CIST_OAH) | (v))
#define getoah(st)  ((st) & CIST_OAH)
  • global_State
/*
** 'global state', shared by all threads of this state
*/
typedef struct global_State{···}
  • lua_State ,
/*
** 'per thread' state
*/
struct lua_State {
CommonHeader;
···
}
  • CommonHeader , 就通用头,所有可回收的objects。
/*
** Common Header for all collectable objects (in macro form, to be
** included in other objects)
*/
#define CommonHeader    GCObject *next; lu_byte tt; lu_byte marked
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值