Mercurial > spidermonkey-playground
diff spidermonkey-playground.cpp @ 2:1f3e9c8df4f0
Script is now read from tcb.js.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 18 Jun 2009 22:11:08 -0700 |
parents | 7444443d2646 |
children | 7237a81919b2 |
line wrap: on
line diff
--- a/spidermonkey-playground.cpp Thu Jun 18 20:35:22 2009 -0700 +++ b/spidermonkey-playground.cpp Thu Jun 18 22:11:08 2009 -0700 @@ -3,6 +3,9 @@ #include "wrapper.h" +#define MAX_SCRIPT_SIZE 50000 +#define TCB_FILENAME "tcb.js" + /* The class of the global object. */ static JSClass global_class = { "global", JSCLASS_GLOBAL_FLAGS, @@ -92,10 +95,17 @@ /* Your application code here. This may include JSAPI calls to create your own custom JS objects and run scripts. */ - char *source = "print('Hello World.'); wrap({}, {});"; + FILE *f = fopen(TCB_FILENAME, "r"); + if (!f) + return 1; + + char source[MAX_SCRIPT_SIZE]; + fread(source, MAX_SCRIPT_SIZE, 1, f); + fclose(f); + jsval rval; if (!JS_EvaluateScript(cx, global, source, - strlen(source), "<string>", 1, + strlen(source), TCB_FILENAME, 1, &rval)) { printf("An error occurred.\n"); return 1;