So last week I posted this stackoverflow question. For those who don't already know you can inject AHK functions into Internet Explorer such that they can be called from JavaScript. An Example:
Code: Select all
#Persistent
html =
(
<html>
<head>
<script>
document.setVar = function`(name,val`){
document[name]=val;
}
</script>
</head>
<body>
<h1>Hello!</h1>
</body>
</html>
)
ie := ComObjCreate("InternetExplorer.Application")
ie.navigate("about:blank")
sleep, 2000
msgbox, %html%
ie.document.writeln(html)
ie.visible := true
ie.document.setVar("someFunc",Func("someFunc"))
someFunc(){
msgbox, "hello"
}
My question is, why does this work so well?! What are the conditions that ie.document.setVar("someFunc",Func("someFunc")) actually injects the function into JS, like on a low level I mean. Does someFunc need to be wrapped in some IDispatch? Or does it have to have some other COM properties?
The reason I am asking is because I can't for the life of me figure out how I can do the same in Ruby... So far everything I have tried seemed like it could work, but nothing really did... Any ideas?
Note:
I am using Ruby on Windows (Cygwin), FYI.
EDIT:
I've also seen that Function objects are a little different in AHK. Is this part of the reason? Do passed functions have to be actual objects which have a Call() and a __Call() method?
Code: Select all
class YourClassName {
Call(a, b) { ; Declare parameters as needed, or an array*.
;...
}
__Call(method, args*) {
if (method = "") ; For %fn%() or fn.()
return this.Call(args*)
if (IsObject(method)) ; If this function object is being used as a method.
return this.Call(method, args*)
}
;...
}