Page 1 of 1

[AHK_H v2] Macro Functions

Posted: 09 Oct 2017, 16:02
by HotKeyIt
I have implemented experimental macro functions.
Now 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.

Code: Select all

myfun("MyValue")
fun("AnotherValue")
MsgBox var
myfun(value:=""){
	fun(value)
	MsgBox var
}
macro fun(value){
	var:=value
}
Let me know what you think about it ;)
Deref function example
Alternative deref function example

Re: [AHK_H v2] Macro Functions

Posted: 09 Oct 2017, 16:05
by HotKeyIt
Restored reply from Helgef from google cache.

This is nice. :thumbup:
Eg, to reduce index transform clutter in loops,

Code: Select all

loop 8
	Msgbox 2**i()
macro i(){
	return A_Index-1
}
This crashes,

Code: Select all

macro m(){
	0
}
an error would be nicer, or if it was just inlined ;)
Cheers.

Re: [AHK_H v2] Macro Functions

Posted: 09 Oct 2017, 16:05
by HotKeyIt
That seems to be a problem in v2, it is not related to macro, I have opened a bug report: https://autohotkey.com/boards/viewtopic ... 33#p158449