lua-users home
lua-l archive

Re: How to understand "yield in c" at Lua 5.3 manual document

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Mar 16, 2016 at 2:55 PM, Wangbo <wangbo.red@gmail.com> wrote:
> It is difficult for me to read chapter "yield in c". especially API
> lua_yieldk, lua_callk and lua_pcallk
> Can someone give me some code/scenario that need this function ? so i can
> debug it by gdb to study the implementation.
Hello,
I have created C module with a function which yields Fibonacci numbers
up to 1 billion.
https://github.com/starius/lua-yield-in-c-example/blob/master/fib.c
How to use this module:
https://github.com/starius/lua-yield-in-c-example/blob/master/test.lua
There are other cases of "yield in C". For example, lua_pcallk can be
used for the following. Consider you have C function which gets a Lua
callback in its arguments. The C function calls Lua callback. If you
want to support yielding Lua functions, you have to call them with
lua_pcallk instead of lua_pcall.
-- 
Best regards,
Boris Nagaev

AltStyle によって変換されたページ (->オリジナル) /