Named parameters in Lua #11414
tarleb
started this conversation in
Show and tell
Replies: 1 comment
-
|
Synchronicity! The other day after having written a script which creates a lot of tables1 I was going to ask if something like this was possible but decided not to because I was afraid that my wanting this feature was too niche. Footnotes
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I find the Lua functions sometimes slightly unpleasant to use, because they require to remember the correct order in which the function parameters have to be passed. I find parameter names often easier to remember than their order, so I wrote a small function that can modify any pandoc Lua function to make it usable with named parameters.
Lua allows to omit the parentheses of a function call if the argument is a table literal. I.e., instead of
my_fun({a = 1})one can writemy_fun{ a = 1 }, and the method given here allows to used this feature. The belownamed_parametersfunction wraps functions, so that the parameters can be passed via their name mentioned in the documentation. In other words, instead of writingit becomes possible to write
Using the original function is still possible: if more than one argument is given, or if a required parameter cannot be found in the arguments table, then the unwrapped function is called as it would be normally.
Each function has to be wrapped:
pandoc.Link = named_parameters(pandoc.Link), which can be done for all functions in a module viaDefinition for
named_parameters:Beta Was this translation helpful? Give feedback.
All reactions