[Request] Module Export

Propose new features and changes
User avatar
Chunjee
Posts: 61
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, this is how it works in Node:

Code: Select all

var myLodash = require('lodash'); // searches recursively in parent directory for lodash library and imports as user specified object. myLodash.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 12 Nov 2018, 12:09, edited 9 times in total.
User avatar
nnnik
Posts: 3427
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

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 7 guests