[Request] Module Export

Propose new features and changes
User avatar
Chunjee
Posts: 69
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

[Request] Module Export

17 Oct 2018, 08:29

Hello,

I am officially requesting Moduled Exports in the likeness of Node.js: https://nodejs.org/api/modules.html
It would be nice to be able to use external functions without following the naming convention the function creator chose.

Psuedocode:

Code: Select all

Class exampleClass{
	
	__New() {
	}
	

	exampleMethod(parameter) {
		;do something
	}
	
Export(exampleClass)

Code: Select all

exampleFunction(parameter1, parameter2) {
	;do something
}

Export(exampleFunction)

Code: Select all

Import(module.ahk)
myclassinstance := new exampleClass()

mynamedfunction := Import(function.ahk)
mynamedfunction("foo","bar")
#import %filename% as %varname% also a good suggestion.



As a note, its easy in javascript as everything including functions can be saved as objects and transported elsewhere:

Code: Select all

function myCoolFunction() {
// do something
}
module.exports = {
	myCoolFunction: myCoolFunction
};

Code: Select all

var myCoolFunctionInstance = require('myCoolFunction');
// searches recursively in parent directory for lodash library and imports as user specified object.
myCoolFunctionInstance.doSomething()

In addition: I have been working around the outdated way AHK sources code from other files, but increasingly I am coming up against an issue where the same function cannot be defined twice:
Known limitation: Currently, the name of each subroutine (label) must be unique among those of the entire script. The program will notify you upon launch if there are duplicate labels.
This turns into an issue when for example two libraries share a dependency on a third library.


Notes and links:
https://autohotkey.com/docs/Functions.htm#lib
Last edited by Chunjee on 14 Nov 2018, 16:14, edited 10 times in total.
User avatar
nnnik
Posts: 3685
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Module Export

17 Oct 2018, 08:37

#import %filename% as %varname% would be my prefered syntax for this.
All files loaded like this receive their own scope and settings.
They also receive their own A_Variables and functions.
In this syntax the person creating the library does not need to care about the way it is imported and we can keep the current libraries unchanged.
Recommends AHK Studio
User avatar
Chunjee
Posts: 69
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: [Request] Module Export

18 Dec 2018, 15:23

https://autohotkey.com/docs/commands/_Include.htm
#IncludeAgain allows multiple inclusions of the same file, while being the same as #Include in all other respects.
I'll see if this can be leveraged in any way.
User avatar
kczx3
Posts: 717
Joined: 06 Oct 2015, 21:39

Re: [Request] Module Export

18 Dec 2018, 16:48

Can you explain how that may be helpful?
User avatar
Chunjee
Posts: 69
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: [Request] Module Export

19 Dec 2018, 15:25

For some reason, I thought it would allow multiple a the same function to be defined more than once but I was wrong.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 12 guests