All AutoHotkey objects implement IDispatch. There is no need to implement it unless you want to change the behaviour.
the same way as x.y
: it first calls IDispatch::GetIDsOfNames, and then IDispatch::Invoke. AutoHotkey objects assign an ID to each unique name, then map the ID back to a name when invoked. The flags for Invoke specify to invoke a property; there is no flag for array indexing.
Functions are invoked via IDispatch with DISPID_VALUE instead of mapping a name to an ID. DISPID_VALUE maps to either Call
depending on the type of invocation. Since COM supports parameterised properties, clients such as JScript, VBScript and C# will specify the flags for "either property or method". In such cases, AutoHotkey tries one and then the other. So in other words, the JScript call v = arr(n)
can result in a call to arr.__Item[n]
. However, the statement arr(n)
(where the return value is discarded) is only ever a method call.
That's probably your answer for reading arrays: use arr(n)
, not arr[n]
For writing to arrays, I was surprised to find that arr(n) = value
I feel like the issue with JS objects is somehow related to this note:
Which objects are like callback functions
? It's too vague. It tells you how to invoke a callback, but nothing about any other type of object or operation.
translates to a method call with DISPID_VALUE if obj is a COM object (IDispatch).
How did you try to call the object itself? I see no such attempt in your screenshot; you only evaluate the object (.AHK
), retrieve its property (.stuff
), and invoke two methods (.invoke()
). I'd guess that .invoke()
was supposed to do something special, since it seems you've defined things
but not invoke
If you want to call the object itself, you just call the object itself: .AHK()
. In JScript this would result in a call to IDispatch::Invoke with DISPID_VALUE, which would translate to Call
(I think the flags would only specify a method call in this context).