From: demallien <dem...@me...> - 2010-08-25 14:53:18
|
Hi Stefan, I don't have a Mac in front of me to test, but I noticed that -invokeUndefinedMethodFromWebScript:withArguments: isn't a class method, it's an instance method of the WebScripting protocol, so you should just be able to do declare this: def invokeUndefinedMethodFromWebScript_withArguments_(name, args) OSX::NSLog("Check invokeUndefinedMethodFromWebScript for #{name}!!") puts name puts args.inspect end as a method on the object that you set using setValue:forKey: Your two class methods shouldn't actually need to be defined - they default to returning YES anyway. Anyway, try that, and let us know if it helps.... On 25 Aug, 2010,at 03:49 PM, Stefan Bracke <ste...@gi...> wrote: 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 selfisKeyExcludedFromWebScript(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 ------------------------------------------------------------------------------ Sell apps to millions through the Intel(R) Atom(Tm) Developer Program Be part of this innovative community and reach millions of netbook users worldwide. Take advantage of special opportunities to increase revenue and speed time-to-market. Join now, and jumpstart your future. http://p.sf.net/sfu/intel-atom-d2d _______________________________________________ Rubycocoa-talk mailing list Rub...@li... https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |