0

for an app, i have to search for a function in JavaScript syntax in a NSString.

In java, i've done it this way:

import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
private Scriptable script;

public boolean bla(String name) {

  Object obj = script.get(name, script);
  if (!(obj instanceof Function)) {
      return false;
  } 

return true;
}

Is there an easy way to convert this to objective-c? It's in Cocoa touch, so i can't use webkit.

thanks

m0e

Tim
  • 35,413
  • 11
  • 95
  • 121
m0e
  • 15
  • 4
  • Do you mean, "can I **check** ..." ? Also I don't understand what this has to do with JavaScript. – Pointy Jul 11 '12 at 17:03
  • oh yes, sry autocorrection ...... – m0e Jul 11 '12 at 18:23
  • Oh, right, overlooked that. It's [possible to compile JavaScriptCore on iOS](http://www.phoboslab.org/log/2011/06/javascriptcore-project-files-for-ios), so that might be an option. It's relatively heavy-weight, but quite easy to use. – omz Jul 11 '12 at 19:09
  • You could try http://parsekit.com/. I haven't tested it though. – user123444555621 Jul 11 '12 at 19:23
  • Seems kinda dangerous to say "This looks like a JavaScript functon so I think I'll execute it." Seems like you should KNOW. – Hot Licks Jul 11 '12 at 19:32

1 Answers1

0

Do you only want to know if there is a function or do you need to do further processing? Your given example works because the library you are using turns the code into a full-fledged Javascript object and checks for the function. But if you just want a quick and dirty check if the function is there, I would recommend using a substring checking routine (NSString's rangeOfString). Otherwise you are going to have to pull in a whole library from somewhere that parses JavaScript.

jwj
  • 528
  • 3
  • 13
  • i really need to check if the function is written in javaScript and has the right syntax. Do you know such a library? – m0e Jul 11 '12 at 18:29