Plugin event|library script registration via funtion decorator #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Yet another extension to reduce workload for creating a plugin. This function takes a CSV list of patterns, pulls the matching
.nss
files, scans the contents for specified decorators@EVENT[...]
and, optionally,@LIBRARY[]
, and registers the event and library scripts scripts for that plugin.Tested to work as intended as long as the decorator is in a comment immediately before the function definition. Can theoretically be used in function prototypes, but hasn't been tested there.
Had to revert to calling
AddLibraryScript
directly (vsRegisterLibraryScript
) because of issues withSetScriptParam
not passing the correct library for the current VM session, so the library script overwrite notifications are bypassed. Let me know if you have a better way to implement this.The lines are bit a long due to the nature of regex and
JsonPointer
addressing. I shortened them quite a bit withSubstituteString
, but they're still a bit abnormally lengthy.Could possibly add another regex capture group to prevent a second scan of the document for the different decorators, but I'll leave that for commenting. I left them separate for now given how different the regex constructs are between the two decorators.
Using this function, all
RegisterEventScript
andRegisterLibraryScript
calls, and the entireOnLibraryScript
function, were completely done away with, so there was no library numbering to be managed, greatly reducing the maintenance requirements for library loading.This is my current
OnLibraryLoad
for my testing plugin, which registers 25 event scripts and 32 library scripts with a single call and no library management: