swift - Calling a JS framework method through JavaScriptCore results in unexpected output -
i trying leverage of functionality found in chroma.js in macos app.
i have following initial setup
func initializejs() {     if let jssourcepath = bundle.main.path(forresource: "chroma", oftype: "js") {         {             let jssourcecontents = try string(contentsoffile: jssourcepath)             self.jscontext?.evaluatescript(jssourcecontents)         }         catch {             print(error.localizeddescription)         }     } }   i want test whether works trying use scale method chroma offers calling function:
open func testscale(withcolors colors: [nscolor], mode:string = "lab") {      // transform colors array array compatible chroma.js     let arr = colors.map({ (color) -> string in         return color.tohexstring()     })      // call "scale" method array     if let scale = self.jscontext?.objectforkeyedsubscript("chroma").invokemethod("scale", witharguments: arr) {         print(scale)     }  }   when printing "scale" constant i'd expect array of strings, instead i'm getting actual function body:
function (v) {  var c;  c = chroma(getcolor(v));  if (_out && c[_out]) {  return c[_out]();  } else {  return c;  }  }   i tried calling scale method (instead of using invokemethod), got absolute same results.
if let scale = self.jscontext?.objectforkeyedsubscript("chroma").objectforkeyedsubscript("scale").call(witharguments: arr) {     print(scale) }   what doing wrong here? sort of feel i'm never calling scale method properly, i'm not sure why.
 
 
Comments
Post a Comment