[a129] How to port?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

[a129] How to port?

Post by hoppfrosch » 22 Mar 2021, 00:49

Hi,

I am trying to port code to A129 (from AHK1) - I fail to port the following piece of code, as I do not fully understand, how this works:

Code: Select all

;make default key value 0 instead of a blank string   <--- thats comment from original code ...
l_arr := {base:{__Get:Func("Abs").Bind(0)}}
Any help appreciated

TIA
hoppfrosch
Last edited by hoppfrosch on 23 Mar 2021, 02:41, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to port? a129

Post by swagfag » 22 Mar 2021, 04:54

in v1, the get metafunction is invoked whenever an object's key that doesnt exist is attempted to be accessed(ie myObj.nonexistent_key or myObj["nonexistent_key"]) and one of that object's bases defines such a meta function, which is why the additional object is required there. the meta-get property must contain a Func Reference or a BoundFunc Reference, so Func("Abs").Bind(0) spares u having to write:

Code: Select all

this_func_name_is_now_taken(Args*) {
	return 0
}

u can port it like so:

Code: Select all

#Requires AutoHotkey v2.0-a129-78d2aa15
l_arr := {base: {__Get: (*) => 0}}
but that doesnt mean its going to do what u want it to do(but since u dont know what u want it to do..., u can see how thats a bit of a predicament)
in v2, meta-get can be defined and called on the object itself, too, so it might be possible that u dont actually need the extra base object
in v2, meta-get is called when nonexistent properties are accessed(ie myObj.nonexistent_prop and myObj.%'nonexistent_prop'%), which is different in the case of the indexing operator(which is handled by __Item)
lastly, as the name of ur variable suggests, u might actually not need an object but an Array
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: How to port? a129

Post by hoppfrosch » 22 Mar 2021, 05:28

Thanks swagfag - gonna try to understand what you wrote and after that I might understand what I want to do :crazy: :lol:
Post Reply

Return to “Ask for Help (v2)”