A function definition can be prefixed with 'macro ' (followed by space, not tab!) to create a macro instead of function. Macro will use caller's scope for all variables except for parameters, function parameters will be resolved to local variables. Dynamic variable references will also use caller's scope. Global and static variables are not supported in macros.
macro function ...
;Deref function example: fun() fun(){ MyVar:="AutoHotkey_H" MsgBox deref("Calling deref ``% from %A_ThisFunc% in %MyVar%") } macro deref(__deref__,__out__:="",__set__:=""){ Loop Parse, __deref__, "%" If __set__&&!__set__:=false __out__.=%A_LoopField% else if SubStr(A_LoopField,-1)="``" __out__.=SubStr(A_LoopField,1,-1) "%" else __out__.=A_LoopField,__set__:=true return __out__ } ;Alternative deref function example: fun() fun(){ MyVar:="AutoHotkey_H" MsgBox deref(["A_ThisFunc","MyVar"],"Calling deref ``% from `a in `a","`a") } macro deref(__vars__,__text__,__delimiter__,__out__:=""){ Loop Parse, __text__, __delimiter__ if A_LoopField __delimiter__:=__vars__[A_Index],__out__.=A_LoopField %__delimiter__% return __out__ }