Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Openresty coroutine usage #329

Merged
merged 3 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.lua]
indent_style = space
indent_size = 2

[kong/templates/nginx*]
indent_style = space
indent_size = 4

[*.template]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
7 changes: 7 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ unused_args = false
redefined = false
max_line_length = false

globals = {
"ngx",
"coroutine._wrap",
"coroutine._yield",
"coroutine._create",
"coroutine._resume",
}

not_globals = {
"string.len",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
[#326](https://github.com/Tieske/Penlight/pull/326)
- added an extra changelog entry for `types.is_empty` on the 1.6.0 changelog, due
to additional fixed behaviour not called out appropriately [#313](https://github.com/Tieske/Penlight/pull/313)
- `path.packagepath` now returns a proper error message with names tried if
it fails

### Fixes

- Fix: `stringx.rfind` now properly works with overlapping matches
[#314](https://github.com/Tieske/Penlight/pull/314)
- Fix: `package.searchpath` (in module `pl.compat`)
[#328](https://github.com/Tieske/Penlight/pull/328)
- Fix: OpenResty coroutines, used by `dir.dirtree`, `pl.lexer`, `pl.permute`. If
available the original coroutine functions are now used [#329](https://github.com/Tieske/Penlight/pull/329)

## 1.7.0 (2019-10-14)

Expand Down
7 changes: 5 additions & 2 deletions lua/pl/dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ local sub = string.sub
local os,pcall,ipairs,pairs,require,setmetatable = os,pcall,ipairs,pairs,require,setmetatable
local remove = os.remove
local append = table.insert
local wrap = coroutine.wrap
local yield = coroutine.yield
local assert_arg,assert_string,raise = utils.assert_arg,utils.assert_string,utils.raise

-- check on OpenResty coroutine versions, and use originals if possible
local wrap = coroutine._wrap or coroutine.wrap
local yield = coroutine._yield or coroutine.yield


local dir = {}

local function makelist(l)
Expand Down
6 changes: 5 additions & 1 deletion lua/pl/lexer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
-- See the Guide for further @{06-data.md.Lexical_Scanning|discussion}
-- @module pl.lexer

local yield,wrap = coroutine.yield,coroutine.wrap
local strfind = string.find
local strsub = string.sub
local append = table.insert

-- check on OpenResty coroutine versions, and use originals if possible
local wrap = coroutine._wrap or coroutine.wrap
local yield = coroutine._yield or coroutine.yield


local function assert_arg(idx,val,tp)
if type(val) ~= tp then
error("argument "..idx.." must be "..tp, 2)
Expand Down
11 changes: 7 additions & 4 deletions lua/pl/permute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ local tablex = require 'pl.tablex'
local utils = require 'pl.utils'
local copy = tablex.deepcopy
local append = table.insert
local coroutine = coroutine
local resume = coroutine.resume
local assert_arg = utils.assert_arg

-- check on OpenResty coroutine versions, and use originals if possible
local co_create = coroutine._create or coroutine.create
local co_yield = coroutine._yield or coroutine.yield
local co_resume = coroutine._resume or coroutine.resume


local permute = {}

Expand Down Expand Up @@ -41,9 +44,9 @@ end
function permute.iter (a)
assert_arg(1,a,'table')
local n = #a
local co = coroutine.create(function () permgen(a, n, coroutine.yield) end)
local co = co_create(function () permgen(a, n, co_yield) end)
return function () -- iterator
local _, res = resume(co)
local _, res = co_resume(co)
return res
end
end
Expand Down