Creating Plug-Ins

digitaldon37

Active Member
Licensed User
Longtime User
I wasn't sure to put this under Q&A or under wishlist...but I was wondering if it were possible to create a plug-in framework for B4PPC applications. Sometimes you want to give the user the ability to create scripts or applets to run within your application.

For example, on the pocket weather forecast project, I had some requests for different types of screens and to update the registry so that other applications could benefit from it. My first thought was to add a browser control to a new form, which could run a javascript file (I tested this when working on a wiki program). I could expose variables (temp forecast, etc) by substitution key words in the javascript file.

But this isn't really a true plug-in architecture, so I was wondering if anyone else had thought of doing this and had anything to share?

Here is a link I found on how to implement plug-ins in VB.NET: How To Create Application Plug-ins In VB.NET

Another link: Writing Plugin-Based Applications in .NET

Update: Found this quote "In the end I am very pleased with this library, even though it is pretty useless except for a few specialist applications that require runtime scripting" - in the DLL forum from Agraham. Maybe this is something that can be used for plug-ins?
 
Last edited:

agraham

Expert
Licensed User
Longtime User
My BasicLib library can do scripts but can't do a real plug-in as it cannot access the apps variables.

The Watcher in my Debug library can access a compiled apps variables, get and set its controls properties and run some of their methods. The Caller in the same library can run a compiled apps Subs.

Taking bits from each might make the basis for a Plugin library. The articles you found are not really relevant to Basic4ppc (assuming you want users to be able to write plug-ins. I'll think about possible architectures when I have some time.
 

agraham

Expert
Licensed User
Longtime User
My BasicLib library can do scripts but can't do a real plug-in as it cannot access the apps variables.
I've had a think about this and this statement is wrong. A script can call back into a Basic4ppc app by firing an event and can pass two parameters to that event. The Basic4ppc app can read and write script variables (originally intended for debugging) and so pass data to and fro so I have already implemented sufficient interaction between a script and the runing app.

So if you could define a plug-in interface in terms of commands and data that could be passed between a script and the compiled app then a user could write an add-on script that could be loaded and run by a user command at runtime and interact with the pre-compiled app to extend it.

A script could be arranged to run either on a separate thread in parallel with the main app or on the main thread. However a script (at the moment - this could be chaged) runs to completion without a Sleep or a DoEvents keyword. This is necessary if it is running on the main thread but if on a separate thread a wait mechanism of some sort could be provided.

If you are interested I could knock up an app that demonstrated some of this.
 

digitaldon37

Active Member
Licensed User
Longtime User
I've had a think about this and this statement is wrong. A script can call back into a Basic4ppc app by firing an event and can pass two parameters to that event. The Basic4ppc app can read and write script variables (originally intended for debugging) and so pass data to and fro so I have already implemented sufficient interaction between a script and the runing app.

So if you could define a plug-in interface in terms of commands and data that could be passed between a script and the compiled app then a user could write an add-on script that could be loaded and run by a user command at runtime and interact with the pre-compiled app to extend it.

A script could be arranged to run either on a separate thread in parallel with the main app or on the main thread. However a script (at the moment - this could be chaged) runs to completion without a Sleep or a DoEvents keyword. This is necessary if it is running on the main thread but if on a separate thread a wait mechanism of some sort could be provided.

If you are interested I could knock up an app that demonstrated some of this.

I would be interested. Thanks!
 

agraham

Expert
Licensed User
Longtime User
Here's a first stab at a template for plugins. You will need my http://www.b4x.com/forum/additional-libraries/3045-scripting-library-b4ppc.html#post17029

Run PlugInDemo then File->Load->test.src and press Run.

The interface to the plugin script is via the Plugin module which will need altering to suit the interface to the plugin that you define. You should not need to alter the Script module except to add new CallHost commands if you want.

There is no error handling at the moment. How errors are handled is probably best determined by experience of use.

Host data access is a bit clumsy but that is unavoidable without the indirect access to variables that I have requested in the Wishlist forum topic.

The next thing I will play with is an option to choose to run the script on a Thread or not.
 

Attachments

  • Plugin1.0.zip
    5.3 KB · Views: 270

digitaldon37

Active Member
Licensed User
Longtime User
Here's a first stab at a template for plugins. You will need my http://www.b4x.com/forum/additional-libraries/3045-scripting-library-b4ppc.html#post17029

Run PlugInDemo then File->Load->test.src and press Run.

The interface to the plugin script is via the Plugin module which will need altering to suit the interface to the plugin that you define. You should not need to alter the Script module except to add new CallHost commands if you want.

There is no error handling at the moment. How errors are handled is probably best determined by experience of use.

Host data access is a bit clumsy but that is unavoidable without the indirect access to variables that I have requested in the Wishlist forum topic.

The next thing I will play with is an option to choose to run the script on a Thread or not.

Thanks! I'm trying to catch up on some other things but I will take a look at this and comment on
 
Top