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

Add a basic implementation of load for text chunks #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Aeledfyr
Copy link
Contributor

Implements load (and _G for tests).

load is added as a separate module in the stdlib, with Lua::load_load mirroring Lua::load_io; Lua::core doesn't include load, but Lua::full does.

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