-
Notifications
You must be signed in to change notification settings - Fork 242
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
Replace coroutines with iterators #344
Conversation
OpenResty's implementation of coroutines is incompatible with Lua's.
Thanks for this. I actually banged my head against this just last night and went to bed without figuring out what was going screwy. In light of this I poked at the same problem today and this solves it. I'm still kind of foggy on why, but my app using coroutines does seem related. One question though: might it be useful to keep the OpenResty compatibility shim: not for use in Penlight itself but to provide to apps? |
No, because at Kong we've reached the conclusion that these wrappers do not work correctly. These OpenResty functions are fundamentally incompatible, it's a waste of time to try to coerce them into precise Lua semantics. (And in my personal opinion, beyond the scope of Penlight anyway; why should OpenResty get special treatment as opposed to all the other applications and games that customize a Lua VM by making it slightly incompatible with the stock language in one way or another...) |
I'll buy that, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx @hishamhm !
## 1.9.1 (2020-09-27) - fix: dir.walk [#350](lunarmodules/Penlight#350) ## 1.9.1 (2020-09-24) - released to superseed the 1.9.0 version which was retagged in git after some distro's already had picked it up. This version is identical to 1.8.1. ## 1.8.1 (2020-09-24) (replacing a briefly released but broken 1.9.0 version) ## Fixes - In `pl.class`, `_init` can now be inherited from grandparent (or older ancestor) classes. [#289](lunarmodules/Penlight#289) - Fixes `dir`, `lexer`, and `permute` to no longer use coroutines. [#344](lunarmodules/Penlight#344) ## 1.8.0 (2020-08-05) ### New features - `pretty.debug` quickly dumps a set of values to stdout for debug purposes ### Changes - `pretty.write`: now also sorts non-string keys [#319](lunarmodules/Penlight#319) - `stringx.count` has an extra option to allow overlapping matches [#326](lunarmodules/Penlight#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](lunarmodules/Penlight#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](lunarmodules/Penlight#314) - Fix: `package.searchpath` (in module `pl.compat`) [#328](lunarmodules/Penlight#328) - Fix: `path.isabs` now reports drive + relative-path as `false`, eg. "c:some/path" (Windows only) - Fix: OpenResty coroutines, used by `dir.dirtree`, `pl.lexer`, `pl.permute`. If available the original coroutine functions are now used [#329](lunarmodules/Penlight#329) - Fix: in `pl.strict` also predefine global `_PROMPT2` - Fix: in `pl.strict` apply `tostring` to the given name, in case it is not a string. - Fix: the lexer would not recognize numbers without leading zero; "-.123". See [#315](lunarmodules/Penlight#315)
## 1.10.0 (2021-04-27) - deprecate: `permute.iter`, renamed to `permute.order_iter` (removal later) [#360](lunarmodules/Penlight#360) - deprecate: `permute.table`, renamed to `permute.order_table` (removal later) [#360](lunarmodules/Penlight#360) - deprecate: `Date` module (removal later) [#367](lunarmodules/Penlight#367) - feat: `permute.list_iter` to iterate over different sets of values [#360](lunarmodules/Penlight#360) - feat: `permute.list_table` generate table with different sets of values [#360](lunarmodules/Penlight#360) - feat: Lua 5.4 'warn' compatibility function [#366](lunarmodules/Penlight#366) - feat: deprecation functionality `utils.raise_deprecation` [#361](lunarmodules/Penlight#361) - feat: `utils.splitv` now takes same args as `split` [#373](lunarmodules/Penlight#373) - fix: `dir.rmtree` failed to remove symlinks to directories [#365](lunarmodules/Penlight#365) - fix: `pretty.write` could error out on failing metamethods (Lua 5.3+) [#368](lunarmodules/Penlight#368) - fix: `app.parse` now correctly parses values containing '=' or ':' [#373](lunarmodules/Penlight#373) - fix: `dir.makepath` failed to create top-level directories [#372](lunarmodules/Penlight#372) - overhaul: `array2d` module was updated, got additional tests and several documentation updates [#377](lunarmodules/Penlight#377) - feat: `aray2d` now accepts negative indices - feat: `array2d.row` added to align with `column` - fix: bad error message in `array2d.map` - fix: `array2d.flatten` now ensures to deliver a 'square' result if `nil` is encountered - feat: `array2d.transpose` added - feat: `array2d.swap_rows` and `array2d.swap_cols` now return the array - fix: `aray2d.range` correctly recognizes `R` column in spreadsheet format, was mistaken for `R1C1` format. - fix: `aray2d.range` correctly recognizes 2 char column in spreadsheet format - feat: `array2d.default_range` added (previously private) - feat: `array2d.set` if used with a function now passes `i,j` to the function in line with the `new` implementation. - fix: `array2d.iter` didn't properly iterate the indices [#376](lunarmodules/Penlight#376) - feat: `array2d.columns` now returns a second value; the column index - feat: `array2d.rows` added to be in line with `columns` ## 1.9.2 (2020-09-27) - fix: dir.walk [#350](lunarmodules/Penlight#350) ## 1.9.1 (2020-09-24) - released to superseed the 1.9.0 version which was retagged in git after some distro's already had picked it up. This version is identical to 1.8.1. ## 1.8.1 (2020-09-24) (replacing a briefly released but broken 1.9.0 version) ## Fixes - In `pl.class`, `_init` can now be inherited from grandparent (or older ancestor) classes. [#289](lunarmodules/Penlight#289) - Fixes `dir`, `lexer`, and `permute` to no longer use coroutines. [#344](lunarmodules/Penlight#344)
Let's avoid using coroutines in Penlight for iterators, and use closures instead. Coroutines in Lua do not compose well at a library level, so they are better left to the application who controls the main loop to own and manage. (An exception to this rule of thumb is libraries which are the main loop, such as Copas.)
For more background on this general issue of coroutine composability, see for example:
This PR also drop OpenResty hacks from Penlight.