ahkExecuteLine

Exported function that executes script from given line pointer.


OutputVar := ahkExecuteLine(LinePointer, Mode, Wait)
Command  Example: DllCall "AutoHotkey.dll\ahkExecuteLine", "PTR", LinePointer, "UInt", 0, "UInt", 0, "PTR"
                  DllCall "AutoHotkey.exe\ahkExecuteLine", "PTR", LinePointer, "UInt", 0, "UInt", 0, "PTR"

Function Example: LinePointer := DllCall("AutoHotkey.dll\ahkExecuteLine", "PTR", LinePointer, "UInt", 0, "UInt", 0, "PTR")
                  VarPointer := DllCall("AutoHotkey.exe\ahkExecuteLine", "PTR", LinePointer, "UInt", 0, "UInt", 0, "PTR")

Parameters

OutputVar

The name of variable in which to store the pointer to next line.

LinePointer

Pointer to Line to start execution from. NULL / false / 0 can be used to get pointer to first line.

Mode

0 - will not execute and return a pointer to next line only.
1 - UNTIL_RETURN
2 - UNTIL_BLOCK_END
3 - ONLY_ONE_LINE

Wait

1 (true) if you want to wait until execution finishes, else FALSE / NULL / 0.

Related

ahkFindFunc, ahkFindLabel, ahkassign, NewThread

Examples

MsgBox 'first Line ' A_TickCount
dll:=NewThread("#Warn 'Unreachable', 'Off'`nPersistent`nMyVar:='Hello World!'`nReturn`nMsgBox MyVar") ; start a new thread and set MyVar variable.
hLine:=0
Loop 4 ; Retrieve pointer to 5-th executable line.
 hLine := dll.ahkExecuteLine(hLine)
dll.ahkExecuteLine(hLine,1,1) ; execute from the 5-th line



; ---------------- Advanced Exaple ----------------
MsgBox 'this line will be executed twice'
; AHK Structures
MsgBox 'this is a test'
global _AHKDerefType := "LPTSTR marker,{_AHKVar *var,_AHKFunc *func,_AHKDerefType *next,UInt symbol},BYTE type,param_count,WORD length"
global _AHKExprTokenType := "{__int64 value_int64,double value_double,struct{{PTR *object,_AHKDerefType *deref,_AHKVar *var,LPTSTR marker,_AHKExprTokenType *circuit_token},{_AHKExprTokenType *outer_deref,LPTSTR error_reporting_marker,size_t marker_length, BOOL is_lvalue}}},UINT symbol"
global _AHKArgStruct := "BYTE type,bool is_expression,WORD length,LPTSTR text,_AHKDerefType *deref,_AHKExprTokenType *postfix"
global _AHKBreakPoint := "INT id,BYTE type,BYTE state,bool temporary"
global _AHKLine := "BYTE mActionType,mArgc,WORD mFileIndex,UINT mLineNumber,_AHKArgStruct *mArg,PTR *mAttribute,_AHKLine *mPrevLine,*mNextLine,*mRelatedLine,*mParentLine,_AHKBreakPoint *mBreakPoint"
global _AHKLabel := "PTR vTable,LPTSTR mName,_AHKLine *mJumpToLine,_AHKLabel *mPrevLabel,*mNextLabel"
global _AHKFuncParam := "_AHKVar *var,WORD is_byref,default_type,{LPTSTR default_str,Int64 default_int64,Double default_double}"
If (A_PtrSize = 8)
	global _AHKRCCallbackFunc := "UINT64 data1,data2,PTR stub,UINT_PTR callfuncptr,BYTE actual_param_count,create_new_thread,event_info,*_AHKFunc func"
else
	global _AHKRCCallbackFunc := "ULONG data1,data2,data3,PTR stub,UINT_PTR callfuncptr,ULONG data4,data5,BYTE actual_param_count,create_new_thread,event_info,*_AHKFunc func"
global _AHKUSerFunc := "PTR *mFunc,int mInstances,_AHKLine *mJumpToLine,_AHKFuncParam *mParam,PTR *mClass,_AHKLabel *mFirstLabel,*mLastLabel,_AHKFunc *mOuterFunc,PTR mFuncs,_AHKVar **mVar,**mLazyVar,**mGlobalVar,**mStaticVar,**mStaticLazyVar,**mDownVar,**mUpVar,Int *mUpVarIndex,Int mVarCount,mVarCountMax,mLazyVarCount,mGlobalVarCount,mStaticVarCount,mStaticLazyVarCount,mDownVarCount,mUpVarCount,bool mIsFuncExpression, UCHAR mDefaultVarType,bool mIsMacro,PTR *mdyna_param,bool mPreprocessLocalVarsDone"
global _AHKVar := A_PtrSize ":{Int64 mContentsInt64,Double mContentsDouble,PTR mobject,PTR mVV},{char *mByteContents,LPTSTR mCharContents},{UINT_PTR mLength,_AHKVar *mAliasFor},{UINT_PTR mCapacity,UINT_PTR mBIV},BYTE mHowAllocated,mAttrib,mScope,mType,LPTSTR mName"

hLine:=ahkExecuteLine() ; get pointer to first line in current script
mLine:=Struct(_AHKLine,hLine)

; Check if this is our script and correct line number as it might be included file or static line that is executes before script starts
While mLine.mFileIndex!=0 || mLine.mLineNumber!=1
  mLine[] := hLine := ahkExecuteLine(hLine) ; reassign next line and update Structure
ahkExecuteLine(hLine,3,1) ; execute first line in current thread