Skip to content

Monkey-patching string breaks core lua iterators #108

Description

@alerque

I would expect the std.string.monkey_patch() function to muck with the default string functions. I hate it, but I expect it.

I just bumped into a project where removing the monkey patch and using std.string() for all function calls that expect the relevant stdlib patched behavior still works completely differently (and crashes).

It turns out running the monkey patch function also changes other core Lua functions including reversing the default output of pairs().

lua-stdlib/lib/std/init.lua

Lines 333 to 335 in a632078

--- An iterator like ipairs, but in reverse.
-- Apart from the order of the elements returned, this function follows
-- the same rules as @{ipairs} for determining first and last elements.

This is needs to stop. Explicitly patching functions when asked is one thing, patching other things in a different scope as a side effect is not.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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