How do you program plug-in modules?

Miscellaneous Forums/General Discussion/How do you program plug-in modules?

I can't get my head around this.

If I have an application that manipulates text in various ways, how would I go about allowing the user to add additional methods (either user made or distributed by me) post compilation?

I can understand if the additions were simple variations of what exists already but with only different variable values. But how could I load new algorithms etc.

You see this sort of feature on software and I've always wondered how it's done.

My application is an encryption device where the user can choose the method (caesar shift, vigenere etc) and I want to have the ability to add new methods as required.

I'm at the design stage and simply can't think of a way to do it.

Cheers

Basil

you might try a script engine like briskVM

I'm sorry if I don't totally know what I'm talking about (because I have never actually done this before)

Couldn't you make seperate EXEs for the plugins and have the main program send info to them and then receive return info. That way the main program really doesn't wory about how the algorithm works just that it returns a usable output.

Do you mean BlitzMax modules, or building DLL's to use as userlibs in BB (through CallDLL)/B+/B3D?

http://en.wikipedia.org/wiki/Dynamic-link_library

I think you set up a plug-in format and plug-in writers will have to conform to that format, or something.

Use Lua.

Couldn't you make seperate EXEs for the plugins and have the main program send info to them and then receive return info. That way the main program really doesn't wory about how the algorithm works just that it returns a usable output.

That's basically what a DLL is.

Plugins are generally done either through DLLs, or through a script language, which basically acts like a DLL anyway except it doesn't require the user to have the tools for building a DLL (although scripts are slower).

Either way, you need to come up with a common interface, which all plugins use and your application can rely on. For example, a very simple interface would be to require the DLL to have one function which is called: "Encrypt:String(dat:String)". Your app would then load plugin X, get the "Encrypt" function, and call it.

Usually you'll have a slightly more advanced system though to organize the plugins. For example you might require that all DLLs have a "GetEncryptionType:String()" function, so you can identify the type of encryption the DLL implements, and catalog and add it to a list of supported encryption methods in your actual application.

I'm not sure exactly how you'd do this in BlitzMax, but there should be commands for loading DLLs and accessing the functions it contains. What you'll probably want to do is load all DLLs within a "Plugins" folder and add them to a list of available encryption techniques.

Thanks for the ideas.

I didn't think of using DLLs. But of course.

Cheers

basil

Generally speaking there are several ways to do it.

BlitzMax offers library support so you could have the user write a normal dll type of library and then open it using BlitzMax's commands.

Otherwise you could either write a script language for them to use (like ARexx on the Amiga?) or perhaps use LUA, or have them write some kind of file which contains the names of functions to call or something.

Also in assembly language and maybe C you can load executable code and make the CPU jump straight to it. Much more low-level though.