luacoco 增强lua的coroutine功能

Coco is a small extension to get True C Coroutine semantics for Lua 5.1.

Coco is both available as a stand-alone release and integrated into LuaJIT.

The stand-alone release is a patchset against the standard Lua 5.1.3 distribution. There are no dependencies on LuaJIT. However LuaJIT depends on Coco to allow yielding for JIT compiled functions.

这个luacoco patch也是匠心独特 以最小的侵入修改让lua支持原生的coroutine,解除了原版的coroutine的几个限制:

* Yield across all metamethods (not advised for __gc).
* Yield across iterator functions (for x in func do).
* Yield across callbacks (table.foreach(), dofile(), ...).
* Yield across protected callbacks (pcall(), xpcall(), ...).
* Yield from C functions and resume back to them.

在实现方面主要是利用以下几个macro来实现修改的:

/*
@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
@* (the data goes just *before* the lua_State pointer).
** CHANGE (define) this if you really need that. This value must be
** a multiple of the maximum alignment required for your machine.
*/
#define LUAI_EXTRASPACE 0


/*
@@ luai_userstate* allow user-specific actions on threads.
** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
** extra when a thread is created/deleted/resumed/yielded.
*/
#define luai_userstateopen(L) ((void)L)
#define luai_userstateclose(L) ((void)L)
#define luai_userstatethread(L,L1) ((void)L)
#define luai_userstatefree(L) ((void)L)
#define luai_userstateresume(L,n) ((void)L)
#define luai_userstateyield(L,n) ((void)L)

再拜下萝卜神!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值