Static Value is Blank

Propose new features and changes
SourceX
Posts: 28
Joined: 21 Jun 2015, 06:50

Static Value is Blank

28 Jul 2015, 06:53

If the functions below are library functions, UseMessage() returns a blank value.

Code: Select all

MsgBox % UseMessage() " | " AutoHotkeyThreadMessage()

UseMessage() {
	static Message := AutoHotkeyThreadMessage()
	; Do stuff with message
   return Message
}

AutoHotkeyThreadMessage() {
	static Message := DllCall("RegisterWindowMessage", "Str", "AutoHotkeyThreadMessage", "UInt")
   return Message
}
Can AutoHotkey be changed to ensure static declarations are evaluated before the body is executed — perhaps right after the function is first called?
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Static Value is Blank

28 Jul 2015, 11:17

What about something like this?

Code: Select all

MsgBox % UseMessage() " | " AutoHotkeyThreadMessage()
 
UseMessage() {
	static Message := AutoHotkeyThreadMessage()
	; Do stuff with message
	return Message
}
 
AutoHotkeyThreadMessage() {
	static Message 
	if (!Message)
		Message:= DllCall("RegisterWindowMessage", "Str", "AutoHotkeyThreadMessage", "UInt")
	return Message
}
HotKeyIt
Posts: 1756
Joined: 29 Sep 2013, 18:35
Contact:

Re: Static Value is Blank

28 Jul 2015, 12:38

You have to put the functions in right order!

Code: Select all

MsgBox % UseMessage() " | " AutoHotkeyThreadMessage()
AutoHotkeyThreadMessage() {
	static Message := DllCall("RegisterWindowMessage", "Str", "AutoHotkeyThreadMessage", "UInt")
   return Message
}
UseMessage() {
	static Message := AutoHotkeyThreadMessage()
	; Do stuff with message
   return Message
}
lexikos
Posts: 6207
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Static Value is Blank

28 Jul 2015, 17:04

It may be possible, but I currently have no plan to do it.

HotKeyIt, SourceX presumably isn't defining the functions in the script:
SourceX wrote:If the functions below are library functions,
i.e. they are auto-included in the order the function calls are first encountered. One would not be defining the functions, but including them in a specific order:

Code: Select all

#Include <AutoHotkeyThreadMessage>
#Include <UseMessage>
It's probably sufficient to manually include only the first one; that way the second will be auto-included later on.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 6 guests