Yifei Kong

May 30, 2017

lua

lua_pcall 是使用 c 中的 setjmp 实现的, 对应在lua 中的函数就是 pcall

pcall/error 大概就相当于其他语言中的 try-catch /throw了

local ok, errorobject = pcall(function() 
    --here goes the protected code 
    ... 
end) 

if not ok then 
    --here goes the error handling code 
    --(errorobject has more information about the error) 
    ... 
end 

协程

对称协程只有一个关键字: transfer, 类似于 goto 语句, 把控制权移交给其他的任意一个协程 …

May 30, 2017

openresty

  1. The *by_lua modules that tweak the nginx behaviour (for ex the rewrite_by_lua that is the lua equivalent of nginx http rewrite) module are always run after the standard nginx modules.
  2. The choice of *by_lua module to use largely depends upon the problem that you are trying to solve. For example …

May 30, 2017

lua coroutine

Lua 的协程是非对称的协程也就是 resume 和 yeild 相当于调用和返回

Python 的协程是对称的协程, 相当于 goto.

Lua中携程相关的函数都放在coroutine包中 coroutine.create(function) 返回一个thread类型的值表示一个协程,并且处于suspend状态。 resume(co, params…) 执行一个协程,并且能够传递参数,返回运行的状态的函数yield返回的结果

May 30, 2017

May 30, 2017