Plugins and Program Extentions
BlitzMax Forums/BlitzMax Programming/Plugins and Program Extentions
| ||
This is a somewhat conceptual problem, but I post it here because it is in regards to BlitzMax specifically. I want to write a program that has X amount of features. Then, at a later date, i release a PLUGIN that can be called from the main program and adds Y amount of more features. I would need to pass information (numbers, paths, image data....) in between the main program and the plugins. Ideally, the main program and the plugins would both be written in BlitzMax. What would be the best way to do this? |
| ||
My approach is to create (or use) a script language and to then write most of your application `in script`, running in your script interpretation/compilation engine. Then when it comes to extending it you can just write other scripts and run them. Then you don't need to worry about trying to get little pieces of executable code to run or to work with each other - although you could do that with processes, excecuting an app, and inter-process communication. My philosophy on plugins is really that from the start, an application should be designed to be as open as possible so that the idea of a `plugin` is obsolete - ie the whole application is in a state of modifiability, and you don't just get to add on features in a specific little menu option, but application-wide. Creating most of your user interface and processing and stuff from scripts would let you make the application maleable like that. |
| ||
How exactly does this "inter-process communication work"? Secondly, how could a script implement features that weren't already thought up when the script interpreter was written? |
| ||
I'm an enormous fan of scripting, but this seems entirely the wrong place for it, both for the reason you gave and for reasons of speed and security. I believe BlitzMax can now write DLL's and that's the way I would do this. Have a standard interface which each DLL needs to comply to. For exampe, every plugin would need an Init function which takes certain parameters and returns an object or whatever. Every plugin needs a Shutdown function, and that doesn't take any parameters (or maybe it does, just an example.) Now it's obviously going to vary depending on exactly what you want the plugins to do, but that's essentially how I would do it. You can do everything with functions the DLL must implement or you could perhaps have a set of function pointers which are passed to the DLL in the Init function, thus giving the DLL the ability to call functions in your main program, which might be responsible for passing images, or whatever. Basically, anything which is always going to be required by every plugin should be set out in the enforced structure of the DLL, and things which the plugin may or may not wish to use could be done via function pointers. Then just put all plugins in a certain folder, and have your program search for all the DLL's in that folder, then dynamically link to the requisite functions in each DLL. If the program detects that one or more required functions is missing or invalid, it writes out to a log that the plugin is invalid and moves on to the next plugin. |
| ||
Here's a quick and simple example of what Gabriel is talking about. Drop all these files into the same directory and run,bmk makelib brightenplugin.bmx bmk makelib grayscaleplugin.bmx to build the plugins. Only tested on Windows but it should work fine on the other two. plugintest.bmx brightenplugin.bmx grayscaleplugin.bmx grayscaleplugin.def AND brightenplugin.def EXPORTS Plugin_Execute=bb_Plugin_Execute Plugin_GetName=bb_Plugin_GetName buildplugins.bat "C:\Program Files\BlitzMax\bin\bmk.exe" makelib brightenplugin.bmx "C:\Program Files\BlitzMax\bin\bmk.exe" makelib grayscaleplugin.bmx |
| ||
I am running a Mac and I got "Compile Error: Identifier 'dlopen' not found". However I do see what you seem to be suggesting. Also what do I do with: bmk makelib brightenplugin.bmx bmk makelib grayscaleplugin.bmx I'll test on windows in the morning.... |
| ||
Sorry, those two lines should be run from the command line/terminal in order to build the plugins. Use this, (I've added it to my original post as well) buildplugins.bat "C:\Program Files\BlitzMax\bin\bmk.exe" makelib brightenplugin.bmx "C:\Program Files\BlitzMax\bin\bmk.exe" makelib grayscaleplugin.bmx You may need to modify the path for the BlitzMax installation. As for the Mac issue. Sorry, I don't have one availible for testing. However, upon a quick Google search, it appears that dlopen/dlsym/etc has been removed in newer versions of Mac OS X. Hopefully, someone else around here can be of help. |
| ||
I say no to dll's, they're not cross-platform and for someone to create one requires more know-how than being able to write something in an easy-to-understand script language. The thing is you have to make your script language feature-filled enough and with enough sort of `programming` features so that it can actually be useful for creating previously unthought-of routines. Obviously it shouldn't just be a bunch of function calls, you need stuff like loops and branches and tests and such ... take javascript for example. |
| ||
BlitzMax can build dynamic libraries for each platform so that's not an issue. |
| ||
A linked-library will also likely be faster than any scripted language (even if not by much). |
| ||
I am running a Mac Well, if you get it working, please let me know :-) |
| ||
I did some more looking around and it looks like BMAx is capable of making dll files but not dylibs (Putting cross-platform out the window). Correct me if I'm wrong. |
| ||
After looking around, it appears you're right. makelib seems to only be supported on Windows. Could a Linux user confirm that? |
| ||
Win32 only. I don't think there's every been any intention of it being otherwise. |
| ||
Bummer :( |
| ||
Is there any other way to get two exes/apps to "talk to each other"? |
| ||
Several TCP UDP Interprocess Communication |
| ||
I think someone already talked about "Interprocess Communication". What is that? |
| ||
I think someone already talked about "Interprocess Communication". What is that? The first paragraphs here explain it pretty well http://msdn.microsoft.com/en-us/library/aa365574%28VS.85%29.aspx although for windows, the same holds true for linux and mac just with different primitives. |
| ||
Correct me if I'm wrong, but you are saying that Interprocess Communications are provided by the operating system, not the applications themselves? |
| ||
Inter-process just means that you have two `processes` running in parallel, like two applications, and somehow they are communicating with each other by some means. That could be that you send messages over the network with TCP, or using the inter-process API provided by the operating system. Most/all operating systems have a library of functions you can use to `send and receive messages` to/from applications - it's faster than using TCP networking stuff. But to use it you do have to access the o/s's API. |
| ||
Well that path doesn't sound very friendly. One last question, is it possible for one program to "call" another program, similar to I think it is called createProcess in blitzplus. In a nutshell it calls another program and grabs it's output. |
| ||
One interesting thing I came up with today is a TSharedBank, which is a TBank that can be shared between different running processes (applications), as part of my BaH.Interprocess module. It acts much like a static bank, the difference being the data can be shared between the processes. Local bank:TBank = CreateSharedBank("mybank", 1000) bank.PokeInt(0, 55) ' etc Fun fun :-) |
| ||
So this is part of yet another wonderful Brucey mod? |
| ||
I found http://www.blitzbasic.com/Community/posts.php?topic=65705#734079 , no multi-platform, but it should work. |
| ||
So this is part of yet another wonderful Brucey mod? Well, I wouldn't say it's wonderful, but it is cross-platform, which is always useful for those of us that don't use Windows. |
| ||
Interestingly enough, I downloaded all of your modules though svn a month ago because it seems like BMax just isn't complete without them. And there it was. Interprocess.mod. I'll check it out. |