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

Adding nameparser configuration entry. #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicolasnoble
Copy link

When embedding Lua into binary, it isn't uncommon to also package Lua files into the final product. There will usually be a custom loader to read the source files from the packaged files.

In order to maintain functionality of luacov in such circumstances, this PR provides a mechanism for the user to provide custom mappings between internal names and an external source location.

For example, if the custom file loader prefixes its files with src:, we can do something like the following:

configuration = {
  nameparser = function(name)
    if name:sub(1, 4) == 'src:' then
      return '/location/of/debug/files/' .. name:sub(5)
    end
  end
}

--- Provides a function to parse filenames.
-- This function is used to parse filenames in the debug hook.
-- It is passed the filename as an argument and should return the parsed filename.
-- The default parser removes leading `@` and replaces path separators with `/`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description here doesn't really match the behavior in the code below:

  • in the code below, the @-stripping parser still takes precedence over the user's custom nameparser whenever a name starts with @, meaning that it is not only a "default" behavior that can be overridden with nameparser, but instead nameparser is just a fallback
  • the slash-conversion behavior happens after the namesparser as well.

I think a less surprising behavior would be:

  • priority order to be that the nameparser takes precedence over the @-stripping (that is, match what's implied in the docs when it calls the @-stripping the "default")
  • slash-conversion can remain after nameparser entries for simplicity (that is, match what is in the code), but that needs to be documented

@hishamhm
Copy link
Member

hishamhm commented Mar 4, 2024

@nicolasnoble Thank you for the PR! Left you a review comment.

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

Successfully merging this pull request may close these issues.

2 participants