Ideas for a plugin system

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Ideas for a plugin system

28 Aug 2015, 12:31

Hi guys,

I have this small tool I wrote long ago that extends the "Active Directory Users and Computers" snap-in with a lot of useful features.
As of now it's a single script, containing a lot of redundant code, so I would like rewrite it with a plugin system.

The only requirement is that it should work for both the interpreted and compiled version.

What I have in my mind is:

1. For the interpreted version, rewrite the script dinamically including the plugins code and then executing the script again, closing the old instance.
2. For the compiled version, get the script from internal resources, rewrite the script dinamically including the plugins code, create a copy of the executable modifying the internal script resource and execute it, closing the old instance.

I'm confident this will work, but it looks kinda hackish. Anybody has a suggestion for a better plugin system?
ABCza on the old forum.
My GitHub.
Coco-guest

Re: Ideas for a plugin system

28 Aug 2015, 12:44

Try searching for lexikos' ObjRegisterActive() or LoadFile()(uses ObjRegisterActive). The thing I like with LoadFile() is that it works like a dynamic #Include. The child script runs in its own process, hence, in some ways if a plugin crashes the main application is unaffected and you can load these child scripts using different AHK binaries(v2, etc.).
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Ideas for a plugin system

28 Aug 2015, 18:55

What's the purpose? You can eliminate redundant code without using "plugins".

Plugins are typically used like modules to extend the program, and in particular are designed so that other authors can add modules to your program. If you're the one who will be writing all of the "plugins", you can just write the script to be modular, use #include and forget about any re-writing of the script.

If the plugins are all to be included internally in the compiled executable, why would you need to rewrite it dynamically? You can include the plugins' code as part of the compilation process (i.e. compile the script after processing plugins).
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: Ideas for a plugin system

29 Aug 2015, 01:19

I would like to release it, giving the possibility to the users to write their own plugin. The main program itself will only manage middle mouse clicks and show a menu built upon the installed plugins.

I was having a look at LoadFile() as per Coco advice but I would need to distribute the interpreter in the compiled version. Any alternative to this?
ABCza on the old forum.
My GitHub.
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Ideas for a plugin system

29 Aug 2015, 03:07

I would need to distribute the interpreter in the compiled version.
Why is that a problem?
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: Ideas for a plugin system

29 Aug 2015, 03:28

lexikos wrote:
I would need to distribute the interpreter in the compiled version.
Why is that a problem?
Not really a problem, just a minus. As of now I'm just evaluating some solutions trying to find the best one.
ABCza on the old forum.
My GitHub.
Coco-guest

Re: Ideas for a plugin system

29 Aug 2015, 04:24

Another option is to not compile your script but instead ship it along with AutoHotkey.exe. Rename the exe to YourScript.exe. Running the renamed executable(in this case without the script parameter), will automatically run YourScript.ahk as long as both of them are in the same directory. You can set the file attributes of YourScript.ahk if you want it as a hidden file. This is much more flexible especially for modular applications since you have the full AHK interpreter at your disposal and since the script is not compiled you can perform dynamic includes, etc. Having the interpreter allows you to launch child scripts as well(say for multiprocessing, if needed).
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: Ideas for a plugin system

29 Aug 2015, 08:41

Ah nice, I like this idea.

I was thinking also to execute the plugin on the fly, creating a temporary executable by copying itself, with the plugin as the script resource, making use of a modified version of lexikos LoadFile. I don't know if it is feasible, I need to understand how this LoadFile works.
ABCza on the old forum.
My GitHub.
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: Ideas for a plugin system

31 Aug 2015, 11:50

I have to ditch the "create a temporary executable" approach, because I would need to create a script parser and it will increase complexity and code size.

I think I will follow Coco's last advice, because I really like it. Changing the icon of the interpreter will be trivial.
ABCza on the old forum.
My GitHub.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Ideas for a plugin system

02 Sep 2015, 00:18

Have tried AHK_H v1?

Example:

main.ahk

Code: Select all

f12::
	InputBox, code
	If (code != "")
		ahkExec(code)
Return
plugin.ahk

Code: Select all

MsgBox, This is a plugin.

test() {
	MsgBox, hi
}
How to compile main.ahk?
First use Win32w\AutoHotkey.exe to run Ahk2Exe.ahk. Then choose Autohotkey.exe as the "Base File (.bin)".

After main.exe is running, press F12, then input #incude plugin.ahk, or any code such as MsgBox abc.
The ahkExec can also call functions in path-to-main.exe\Lib\ folder.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, inseption86, jaka1, LuckyJoe, Rohwedder and 334 guests