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

Expose the Dumper and Parser objects publicly / allow overriding of methods in options #46

Open
kikito opened this issue Jun 22, 2021 · 1 comment

Comments

@kikito
Copy link

kikito commented Jun 22, 2021

On my investigation towards generating a yaml with sorted keys (#45), I realized that I need is the Dumper object used in lyaml/init.lua with a small tweak to the dump_mapping function.

It seems that the only way for me to accomplish this would be to copy-paste the whole implementation of dumper_mt.

I realize that this might be a philosophical point about design, but this feels "wrong" to me.

I see two approaches that would make this less painful:

  • Option a) Exposing Dumper and Parser directly in the lyaml library
local Dumper = require('lyaml').Dumper`)

Then I would be able to build/customize my custom dumper file easily.

This would be trivial to implement, but perhaps a bit "crude". It also opens the door for global modifications of the library (someone could decide to monkeypatch the global Dumper object, instead of using it to build a new Dumper object and using that).

  • Option b) Allowing overriding specific dumper methods via the options parameter
local str = lyaml.dump(tbl, { dump_mapping = my_custom_dump_mapping })

I... honestly don't see a lot of big drawbacks to this one. It seems simple to implement and can be done without exposing global variables for modification.

Would you be open to accepting a PR on any of these directions?

@gvvaughan
Copy link
Owner

Sure, the second seems like a good approach, I’d be happy to merge a PR for that :-)

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

No branches or pull requests

2 participants