[v2] How to Multi-Thread Compiled Code?

Ask for help, how to use AHK_H, etc.
Deafwave
Posts: 5
Joined: 26 Aug 2020, 16:30
Contact:

[v2] How to Multi-Thread Compiled Code?

Post by Deafwave » 28 Aug 2020, 13:13

My current implementation of AHKThread utilizes the .ahk file, which will not work moving forward due to everything being compiled, as my understanding is that AhkThread() can not be utilized on .exe's.

Copying the code directly into the script does not appear to resolve the issue, due to #Include not compiling as expected if inside of parenthesis for the AHKThread() string with the methods I have attempted.

Code: Select all

; Current non-compiled code
#Include <testFolder\defaultObject> ; e.g. defaultObject := { "testValue": 66 }
CritObj := CriticalObject(defaultObject)
thread := AHKThread(A_ScriptDir "\Lib\testFolder\testTwo.ahk", &CritObj "", "threadName_2", true)

Attempted methods that I have tried include, but are not limited to:
Spoiler
Last edited by Deafwave on 28 Aug 2020, 22:59, edited 1 time in total.

kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: [v2] How to Multi-Thread Compiled Code?

Post by kyuuuri » 28 Aug 2020, 21:05

Hello! I think I found what's wrong
Deafwave wrote:
28 Aug 2020, 13:13

Code: Select all

; This works wonderfully when not compiled, but breaks once compiled as the compiler doesn't properly include the file.
; Line Text: #Include <testFolder\testTwo>
; Error: Function library not found.
#Include <testFolder\defaultObject>
CritObj := CriticalObject(defaultObject)

thread := AHKThread("
(
  #Include <testFolder\testTwo>
)", &CritObj "", "threadName_2", false)
From the docs:
#Include <LibName>
LibName
A library file or function name. For example, #include <lib> and #include <lib_func> would both include lib.ahk from one of the function library folders. LibName cannot contain variable references.
Try using:
#Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"

------------------------------------------------- I'm a divider -------------------------------------------------
Deafwave wrote:
28 Aug 2020, 13:13

Code: Select all

; Received a VarSetCapacity error as explained in latest github issue opened by myself (https://github.com/HotKeyIt/ahkdll-v2-release/issues/15)
; I am not positive that you can pass Critical Objects via BinRun

#Include <folder\defaultObject>
CritObj := CriticalObject(defaultObject)

file:=FileRead("testTwo","RAW")
PID := BinRun(&file, &CritObj "")
I don't know where the variable "defaultObject" comes from, I will assume it's declared on "folder\defaultObject".
BinRun requires you to pass the .exe's content as parameter but you are reading a file without an extension.
Try:

Code: Select all

#Include <folder\defaultObject>
CritObj := CriticalObject(defaultObject)

file:=FileRead("testTwo.exe","RAW")
PID := BinRun(&file, &CritObj "")
------------------------------------------------- I'm a divider -------------------------------------------------
Deafwave wrote:
28 Aug 2020, 13:13

Code: Select all

; Error: Illegal character in expression #Include <testFolder\testTwo>
#Include <testFolder\defaultObject>
CritObj := CriticalObject(defaultObject)

script := "
(
    #Include <testFolder\testTwo>
)"
thread := AHKThread(script, &CritObj "", "threadName_2", false)
Try this:

Code: Select all

#Include <testFolder\defaultObject>
CritObj := CriticalObject(defaultObject)

script =
(%`
    #Include <testFolder\testTwo>
)
thread := AHKThread(script, &CritObj "", "threadName_2", false)
------------------------------------------------- I'm a divider -------------------------------------------------
Deafwave wrote:
28 Aug 2020, 13:13

Code: Select all

; This runs the script immediately in-line, it does not care that I'm passing it to AHKThread (it never establishes a second thread)
; This also does not resolve the issue of needing to import Library files into the second thread (e.g. #Include <utils>)
#Include <testFolder\defaultObject>
CritObj := CriticalObject(defaultObject)

script :=
(
    MsgBox("test")
)
thread := AHKThread(script, &CritObj "", "threadName_2", false)
Try this:

Code: Select all

#persistent
#Include <testFolder\defaultObject>
CritObj := CriticalObject(defaultObject)

script :=
(
    MsgBox("test")
)
msgbox("nop")
thread := AHKThread(script, &CritObj "", "threadName_2", false)
In what order do the msgboxes appear?

Deafwave
Posts: 5
Joined: 26 Aug 2020, 16:30
Contact:

Re: [v2] How to Multi-Thread Compiled Code?

Post by Deafwave » 28 Aug 2020, 22:57

Hi Kyuuuri,

I appreciate the insight, but we unfortunately haven't gotten much further. This may be due to an excess of information in my OP, so I have boiled down the information a little better:

As you can see, when it compiles, the #Include <testFolder\defaultObject> works as I desire, bringing that code into the compiled .exe.
However, the #Include <testFolder\testTwo> inside of the script variable does not bring that code into the compiled .exe, causing an error in the compiled .exe.
66, nop, test (UNCOMPILED)
66, nop, ERROR (COMPILED & Moved Away)

For reference to my end goal, I am attempting to compile as such that everything is stored in a compiled state, and none of the code remains in .ahk format. For default #Include at the top of a script file, this works wonderfully as the compiler knows to compile it inside of the script.


kyuuuri wrote:
28 Aug 2020, 21:05
I don't know where the variable "defaultObject" comes from, I will assume it's declared on "folder\defaultObject".
You are correct, I have edited my original post to reflect this.

kyuuuri wrote:
28 Aug 2020, 21:05
BinRun requires you to pass the .exe's content as parameter but you are reading a file without an extension.
I'll keep this in mind, but there is currently a conflict with the latest v2.110 Merge that I would need to account for in order to properly try BinRun, I may revert my Custom ahkdll alpha bin to a previous commit for testing this weekend.

In what order do the msgboxes appear?
test, nop (UNCOMPILED)
nop, test (as desired!) (note the quotes) (UNCOMPILED)

kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: [v2] How to Multi-Thread Compiled Code?

Post by kyuuuri » 28 Aug 2020, 23:24

Deafwave wrote:
28 Aug 2020, 22:57
Hi Kyuuuri,

I appreciate the insight, but we unfortunately haven't gotten much further. This may be due to an excess of information in my OP, so I have boiled down the information a little better:

As you can see, when it compiles, the #Include <testFolder\defaultObject> works as I desire, bringing that code into the compiled .exe.
However, the #Include <testFolder\testTwo> inside of the script variable does not bring that code into the compiled .exe, causing an error in the compiled .exe.
66, nop, test (UNCOMPILED)
66, nop, ERROR (COMPILED & Moved Away)

For reference to my end goal, I am attempting to compile as such that everything is stored in a compiled state, and none of the code remains in .ahk format. For default #Include at the top of a script file, this works wonderfully as the compiler knows to compile it inside of the script.


kyuuuri wrote:
28 Aug 2020, 21:05
I don't know where the variable "defaultObject" comes from, I will assume it's declared on "folder\defaultObject".
You are correct, I have edited my original post to reflect this.

kyuuuri wrote:
28 Aug 2020, 21:05
BinRun requires you to pass the .exe's content as parameter but you are reading a file without an extension.
I'll keep this in mind, but there is currently a conflict with the latest v2.110 Merge that I would need to account for in order to properly try BinRun, I may revert my Custom ahkdll alpha bin to a previous commit for testing this weekend.

In what order do the msgboxes appear?
test, nop (UNCOMPILED)
nop, test (as desired!) (note the quotes) (UNCOMPILED)
The library thing that happens after compiling is because when you use #include with "<>" you are including it from one of the function library folders (predefined). You should try using #Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"
That is exactly what you need.

About the order in the msgboxes, it's normal because without the quotes it parses it in a different way.

Deafwave
Posts: 5
Joined: 26 Aug 2020, 16:30
Contact:

Re: [v2] How to Multi-Thread Compiled Code?

Post by Deafwave » 28 Aug 2020, 23:38

kyuuuri wrote:
28 Aug 2020, 23:24
The library thing that happens after compiling is because when you use #include with "<>" you are including it from one of the function library folders (predefined). You should try using #Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"
That is exactly what you need.
Unfortunately, this is not what I am attempting to accomplish, I have failed to explain this twice.
If I utilize this method, the #Include continues to not house the script upon compiling. Thus requiring an AHK file to be shipped with the program which I do not want.

For example, this default object code has been working as expected this whole time, and it is inside of the Library folder.

Code: Select all

#Include <testFolder\defaultObject> ; defaultObject := { "testValue": 66 }
However, as soon as you attempt one of these two methods, the Ahk2Exe Script Parser fails to Include the file as you I would expect, thus causing the error (UNLESS YOU PACKAGE THE FILE MANUALLY ALONGSIDE THE COMPILED EXECUTABLE).

Code: Select all

script := "
(
    #Include <testFolder\testTwo>
)"

Code: Select all

script := "
(
    #Include Lib\testFolder\testTwo.ahk
)"

Which leads me to believe that I need to make an update to the ScriptParser.ahk to handle this use case.

kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: [v2] How to Multi-Thread Compiled Code?

Post by kyuuuri » 28 Aug 2020, 23:55

Deafwave wrote:
28 Aug 2020, 23:38
kyuuuri wrote:
28 Aug 2020, 23:24
The library thing that happens after compiling is because when you use #include with "<>" you are including it from one of the function library folders (predefined). You should try using #Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"
That is exactly what you need.
Unfortunately, this is not what I am attempting to accomplish, I have failed to explain this twice.
If I utilize this method, the #Include continues to not house the script upon compiling. Thus requiring an AHK file to be shipped with the program which I do not want.

For example, this default object code has been working as expected this whole time, and it is inside of the Library folder.

Code: Select all

#Include <testFolder\defaultObject> ; defaultObject := { "testValue": 66 }
However, as soon as you attempt one of these two methods, the Ahk2Exe Script Parser fails to Include the file as you I would expect, thus causing the error (UNLESS YOU PACKAGE THE FILE MANUALLY ALONGSIDE THE COMPILED EXECUTABLE).

Code: Select all

script := "
(
    #Include <testFolder\testTwo>
)"

Code: Select all

script := "
(
    #Include Lib\testFolder\testTwo.ahk
)"

Which leads me to believe that I need to make an update to the ScriptParser.ahk to handle this use case.
Hello, if #Include FULL_PATH_TO_FILE doesn't work then there is something wrong with the compiler.
Let's try this:
1. Make an empty ahk script called compileMe.ahk
2. Make another ahk script called includeMe.ahk with this line only: msgbox("Im included")
3. Put this in "compileMe.ahk" #Include FULL_PATH_TO_INCLUDEME.AHK ofc replace "FULL_PATH_TO_INCLUDEME.AHK" with the actual full path to includeMe.ahk.
4. Compile compileMe.ahk and open it.
Does it show the msgbox?

Deafwave
Posts: 5
Joined: 26 Aug 2020, 16:30
Contact:

Re: [v2] How to Multi-Thread Compiled Code?

Post by Deafwave » 29 Aug 2020, 00:11

kyuuuri wrote:
28 Aug 2020, 23:55
Hello, if #Include FULL_PATH_TO_FILE doesn't work then there is something wrong with the compiler.
Let's try this:
1. Make an empty ahk script called compileMe.ahk
2. Make another ahk script called includeMe.ahk with this line only: msgbox("Im included")
3. Put this in "compileMe.ahk" #Include FULL_PATH_TO_INCLUDEME.AHK ofc replace "FULL_PATH_TO_INCLUDEME.AHK" with the actual full path to includeMe.ahk.
4. Compile compileMe.ahk and open it.
Does it show the msgbox?
Yes, this works as expected. I believe you are starting to understand the issue.

The issue appears when we try to utilize the "( #Include )" logic due to it staying a string value rather than being compiled down into the script.
E.g.
Spoiler

kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: [v2] How to Multi-Thread Compiled Code?

Post by kyuuuri » 29 Aug 2020, 00:33

Deafwave wrote:
29 Aug 2020, 00:11
kyuuuri wrote:
28 Aug 2020, 23:55
Hello, if #Include FULL_PATH_TO_FILE doesn't work then there is something wrong with the compiler.
Let's try this:
1. Make an empty ahk script called compileMe.ahk
2. Make another ahk script called includeMe.ahk with this line only: msgbox("Im included")
3. Put this in "compileMe.ahk" #Include FULL_PATH_TO_INCLUDEME.AHK ofc replace "FULL_PATH_TO_INCLUDEME.AHK" with the actual full path to includeMe.ahk.
4. Compile compileMe.ahk and open it.
Does it show the msgbox?
Yes, this works as expected. I believe you are starting to understand the issue.

The issue appears when we try to utilize the "( #Include )" logic due to it staying a string value rather than being compiled down into the script.
E.g.
Spoiler
In that case move the var declaration inside the included file. Make the entire included script be a variable declaration like this:

Code: Select all

script := "(
	...
	...
	...
	...
)"
and then include that file.

Deafwave
Posts: 5
Joined: 26 Aug 2020, 16:30
Contact:

Re: [v2] How to Multi-Thread Compiled Code?

Post by Deafwave » 29 Aug 2020, 00:51

kyuuuri wrote:
29 Aug 2020, 00:33
In that case move the var declaration inside the included file. Make the entire included script be a variable declaration like this:

Code: Select all

script := "(
	...
	...
	...
	...
)"
and then include that file.
Unfortunately, this does not accomplish what is necessary either due to the includeMe.ahk file needing to contain #Includes as well, but that is something I thought about.
The true workaround is to make the includeMe.ahk file be completely #Include-less, but that would introduce a ton of bloat to my program. This is why I was looking to validate if I was doing this correctly.

E.g.

Code: Select all

; includeMe.ahk
; This causes utils to be loaded inside of the location of #Include Lib\includeMe.ahk rather than inside of the AhkThread()
#Include <utils>
script := "
(
    msgbox("Im included")
    utilityFunc()
)"
or

Code: Select all

; includeMe.ahk
; Right back where we started!
script := "
(
    #Include <utils>
    msgbox("Im included")
    utilityFunc()
)"

nminhdangit
Posts: 2
Joined: 29 Oct 2022, 03:31

Re: [v2] How to Multi-Thread Compiled Code?

Post by nminhdangit » 14 Nov 2022, 06:09

Did u pass this @Deafwave . I have a same problem Can u give me some sollution

Post Reply

Return to “Ask for Help”