From: Stefan B. <ste...@gi...> - 2010-08-25 13:49:44
|
Hi all, i am still having problems with the WebKit option where i can have Javascript call Cocoa functions. Does anyone have a working RubyCocoa example of how to implement this? In the snippet below for the "isSelectorExcludedFromWebScript"-method, i don't even see the function i called, but generic functions. If i could implement "invokeUndefinedMethodFromWebScriptwithArguments" that would be nice, but no real way of knowing what kind of parameters i have to put in the objc_class_method. Part of class which shows the webpages (that works) ... scriptobject = currentwebkit.windowScriptObject() scriptobject.setValue_forKey(self, "qi3jsobject") homeurl = "somekindofurlwithawebpageandjavascript" currentwebkit.setFrameLoadDelegate(self) ... part of class with the implemented methods required by Webkit (My source is: http://www.thimbleby.net/script ) ... objc_class_method 'isSelectorExcludedFromWebScript', [:BOOL , :sel] def self.isSelectorExcludedFromWebScript(selector) # This does NOT show the functions i called OSX::NSLog("Check if #{selector} is allowed!!") return true; end objc_class_method 'isKeyExcludedFromWebScript', [:BOOL , :char] def self.isKeyExcludedFromWebScript(name) OSX::NSLog("Key excluded is #{name}") return true; end objc_class_method 'webScriptNameForSelector', [:id , :sel] def self.webScriptNameForSelector(selector) OSX::NSLog("Check name for #{selector}!!") return "nicerFunctionName" end # No clue how to implement this method (NSString and NSArray as parameters??) #objc_class_method 'invokeUndefinedMethodFromWebScriptwithArguments', [@@: , @@:] #def invokeUndefinedMethodFromWebScript_withArguments_(name, args) # OSX::NSLog("Check invokeUndefinedMethodFromWebScript for #{name}!!") # puts name # puts args.inspect #end ... and in javascript i did this: qi3jsobject. nicerFunctionName("oh yes!"); I wish i could port this to MacRuby but it's rb-appscript support is missing and it's appleevent support is not ripe for production... Kindly, Stefan |