Skip to content

Unable to use coroutine.wrap in libraries #1292

Closed
@daurnimator

Description

@daurnimator

Trying to use coroutine.wrap inside of libraries loaded with require throws an error.

As an example, take this example that creates+uses an iterator:
Contents of wut.lua:

local t = {}
for i in coroutine.wrap(function()
        local x 
	for i=1, 100 do
		coroutine.yield(i)
	end
end) do
	t[i] = i
end
return t

Contents of access.lua (set as access_by_lua_file):

require "wut"

Running that in openresty results in:

2018/03/28 17:29:25 [error] 16118#0: *1 lua entry thread aborted: runtime error: attempt to yield across C-call boundary
stack traceback:
coroutine 0:
	[C]: in function 'require'
	./access.lua:1: in function <./access.lua:1>, client: 127.0.0.1, server: , request: "GET /get HTTP/1.1", host: "mynode"

The snippet works fine inside of e.g. access.lua itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions