{"action":"created","issue":{"url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/1292","repository_url":"https://api.github.com/repos/openresty/lua-nginx-module","labels_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/1292/labels{/name}","comments_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/1292/comments","events_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/1292/events","html_url":"https://github.com/openresty/lua-nginx-module/issues/1292","id":309238879,"number":1292,"title":"Unable to use coroutine.wrap in libraries","user":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars1.githubusercontent.com/u/127971?v=4","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-28T06:39:36Z","updated_at":"2018-03-28T06:43:02Z","closed_at":null,"author_association":"NONE","body":"Trying to use coroutine.wrap to inside of libraries loaded with `require` throws an error.\r\n\r\nAs an example, take this example that creates+uses an iterator:\r\nContents of wut.lua:\r\n```lua\r\nlocal t = {}\r\nfor i in coroutine.wrap(function()\r\n        local x \r\n\tfor i=1, 100 do\r\n\t\tcoroutine.yield(i)\r\n\tend\r\nend) do\r\n\tt[i] = i\r\nend\r\nreturn t\r\n```\r\n\r\nContents of access.lua (set as `access_by_lua_file`):\r\n```lua\r\nrequire \"wut\"\r\n```\r\n\r\nRunning that in openresty results in:\r\n```\r\n2018/03/28 17:29:25 [error] 16118#0: *1 lua entry thread aborted: runtime error: attempt to yield across C-call boundary\r\nstack traceback:\r\ncoroutine 0:\r\n\t[C]: in function 'require'\r\n\t./access.lua:1: in function <./access.lua:1>, client: 127.0.0.1, server: , request: \"GET /get HTTP/1.1\", host: \"mynode\"\r\n```\r\nThe snippet works fine inside of e.g. access.lua itself.\r\n"},"comment":{"url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/comments/376779094","html_url":"https://github.com/openresty/lua-nginx-module/issues/1292#issuecomment-376779094","issue_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/1292","id":376779094,"user":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars1.githubusercontent.com/u/127971?v=4","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"created_at":"2018-03-28T06:43:02Z","updated_at":"2018-03-28T06:43:02Z","author_association":"NONE","body":"Btw, I **don't** think this is a duplicate of #208, as it can be replicated without the `for` loop.\r\ne.g. if wut.lua contains:\r\n```\r\nlocal the_answer = coroutine.wrap(function() coroutine.yield(42) end)()\r\n```\r\n\r\nWe get the same result."}}
{"actor":{"display_login":"daurnimator"}}