addScript

Exported function that adds new code from string to currently executed script.


OutputVar := addScript(NewCode, WaitExecute)
Function Example: LinePtr := addScript("MsgBox `% A_Now", 1)
                  LinePtr := DllCall("AutoHotkey.dll\addScript", "Str", "MsgBox `% A_Now", "Int", 1, "UPTR")
                  LinePtr := DllCall("AutoHotkey.exe\addScript", "Str", "MsgBox `% A_Now", "Int", 1, "UPTR")

Parameters

OutputVar

The name of the variable in which to store the line pointer to new code, if code could not be added 0 will be stored.

NewCode

New Code to add to currently running script.

WaitExecute (optional)

0 = add code but do not execute.
1 = add code, execute and wait for return.
2 = add code, execute and return immediately (don't wait for code to end execution).

Related

ahkFindFunc, addFile, ahkFindLabel, ahkassign

Examples

dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) ; Load the AutoHotkey module.
DllCall(dllpath "\ahktextdll","Str","","Str","","Cdecl") ; start new, empty thread.
DllCall(dllpath "\addScript","Str","MsgBox Hello World!","Int",1,"CDecl") ; add and execute code

; Same example like above using included AutoHotkey.dll
dll:=AhkThread()
dll.addScript["MsgBox Hello World!",1]

; Add and execute script in current thread
addScript("MsgBox Test",1)