Lua 5.3 源码分析(四)线程 lua_State

Lua 5.3 源码分析(四)线程 lua_State

Lua 的THREAD 类型定义如下:

/*
** 'per thread' state
*/
struct lua_State {
    //1 Lua 类型公共头部
    CommonHeader;
    //2
    global_State *l_G;
    //3
    lu_byte status;
    //4 数据栈:一个动态TValue 数组,所有的Lua object 都是TValue
    int stacksize;
    StkId top;  /* first free slot in the stack */
    StkId stack_last;  /* last free slot in the stack */
    StkId stack;  /* stack base */
    //5 函数调用栈
    CallInfo *ci;  /* call info for current function */
    CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */
    unsigned short nny;  /* number of non-yieldable calls in stack */
    unsigned short nCcalls;  /* number of nested C calls */
    //6 Upvalue info
    UpVal *openupval;  /* list of open upvalues in this stack */
    struct lua_State *twups;  /* list of threads with open upvalues */
    //7 Hook Debug
    lua_Hook hook;
    int basehookcount;
    int hookcount;
    lu_byte hookmask;
    lu_byte allowhook;
    //8 类似PC 寄存器,指向最后一次执行的指令的指令
    const Instruction *oldpc;  /* last pc traced */
    //9 execption
    struct lua_longjmp *errorJmp;  /* current error recover point */
    ptrdiff_t errfunc;  /* current error handling function (stack index) */
    //10 GC
    GCObject *gclist;
};

1. CommonHeader : Lua 类型公共头部。
2. l_G : Lua的全局对象,只存在一份,所有的 L 都共享这个 G。
3. status:每一个THREAD 实际上就是一个死循环解释执行指令的容器,本质上

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值