-
Notifications
You must be signed in to change notification settings - Fork 14
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
Plugin-as-a-Library #145
Comments
Using the techniques you describe, it should be fairly straightforward to write a script that is both callable by another script as well as directly callable by RGP/JW Lua. I don't see what If you create, for example, a modeless palette that runs any of a number of scripts, the palette and any script it runs share the same Lua state. (Unless RGP Lua is enhanced to somehow allow a script to spin off another script in a separate Lua state. This, perhaps, could be done but currently does not exist.) This sharing means that care must be taken that scripts do not define the same global variable names. Use of global variables is much more likely in a script that retains its Lua state than one that doesn't, because the script's state has to survive across chunks. That implies that it would probably be safer for called scripts not to use What you describe is doable. In fact I think @jwink75 may be doing something like that with the Jetstream Controller project. But it will require careful discipline and design. |
How would this be different than simply creating a library function for the underlying plugin? You could then move the entirety of one plugin into a library function, and call it from any new plugin. |
@rpatters1 Thanks for the clarification about state and global variables. I agree that avoiding global variable naming conflicts would be a must for this to work. @Nick-Mazuk One difference is keeping related code grouped together in one file rather than spreading it around between files (ie plugindef, code for creating plugin, and code for displaying/running plugin). Plugins could also control how their scope is used. For example, whether it forces the same state to be reused between all uses or whether it allows a consuming plugin to create a localised copy with its own scope. I have some ideas about how it could look (who knows, it might still fall flat on its face) but I'll leave playing with it until after I've finished writing mixins. |
@ThistleSifter ah I see. Thanks for the clarification! +1 on this feature One other case to consider is what should happen if one of the needed scripts is missing. |
I'm not sure. #287 allows one script to invoke another. What say, you @ThistleSifter, does #287 cover it? |
It's pretty similar, although not exactly the same. Most plugins have options and some have multiple variations on their functionality. What I was describing was also about being able to call a plugin (or a particular part of a plugin's functionality, depending on what it exposed) with parameters. Return values can also be used to report success, failure, status, etc. I think I originally had this in mind so that multiple plugins could be strung together either for a workflow thing, to create a singular combined result, or something else. Whatever is desired. I've just thought of another idea, and that is to separate plugins from their functionality. At the moment, scripts handle most of the 'what', the 'why', and the 'how' of what needs to be done (yes we have library functions, but I'd put these mostly in the category of helper functions). This is getting further into the realms of developing a framework, but splitting these up (perhaps similar to how you might envisage an MVC framework) could also open up more possibilities for both reusing and combining functionality. |
FWIW: The |
I was toying with the idea of writing plugins in such a way so that they can be called by other plugins, aka plugin-as-a-library (not the best name, I know). At the moment this is just an idea and I haven't tried it out, but combined with the state management offered by
finenv.RetainLuaState
, this could open up some interesting opportunities for interactions between plugins.I came across a method for checking if a script is included as a library or whether it is the main script.
Using it in a plugin means the following is possible:
src/my_plugin.lua
If exposing the whole dialog object is not desirable (and I imagine it wouldn't be), we could have a factory for creating wrapping tables:
And if control over preserving/refeshing state is needed, the plugin could return a create function, which then returns a dialog or a wrapper as desired. Then the calling plugin would be in control of when the plugin-as-a-library is retained or garbage collected.
Possible usage:
src/consuming_plugin.lua
The text was updated successfully, but these errors were encountered: