Skip to content

Conversation

@Aeledfyr
Copy link
Collaborator

@Aeledfyr Aeledfyr commented Aug 25, 2024

Implements load (and _G for tests).

load is added as a separate module in the stdlib, with Lua::load_load_text mirroring Lua::load_io; Lua::core doesn't include load, but Lua::full does. This only supports text chunks, but is set up such that adding new variants of load should be straightforward.

It matches PRLua's implementation, likely closer than we actually want, since PRLua's load has some quirks:

  • load can take a function that returns segments of the text; this must be a function, and cannot be a table with a __call metamethod
  • the values returned from the function are concatenated using PRLua's weirdly inconsistent concatenation logic
  • load catches errors thrown by the inner iterator function and returns them as parse errors

This implementation currently matches PRLua in all of those semantics. I should probably change this to use table.concat internally for consistency, though it isn't trivial -- the iterator function can return either nil or an empty string to stop iteration, which makes the semantics not map perfectly to a metatable-generic concat system.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant