iMonkey看起來像是一種在iOS應用程序中嵌入JS運行時的有趣方式,但我找不到任何有關如何實際運行某些JS代碼的示例。如何在iOS應用程序中使用iMonkey
我可以建立/鏈接lib,包含jsapi.h頭文件(來自src目錄),但是當我嘗試一些示例代碼時,它會跳過各種鏈接器錯誤('未定義的架構符號...')蜘蛛猴(見下文)。要清楚的是,這幾乎是來自另一個網站上Mac相關帖子的複製粘貼,我完全不知道是否應該這樣做。我確信我的架構(模擬器)具有正確的靜態庫(通用)。
任何人都知道如何做到這一點?
#include "jsapi.h"
.....
JSRuntime *rt;
JSContext *cx;
JSObject *global;
/* Create a JS runtime. */
rt = JS_NewRuntime(8L * 1024L * 1024L);
/* Create a context. */
cx = JS_NewContext(rt, 8192);
JS_SetOptions(cx, JSOPTION_VAROBJFIX);
/* Create the global object. */
global = JS_NewObject(cx, &global_class, NULL, NULL);
/* Populate the global object with the standard globals,
like Object and Array. */
if (!JS_InitStandardClasses(cx, global))
@throw [[NSException alloc]initWithName:@"JSerror" reason:@"jserrpr" userInfo:nil];
/* Cleanup. */
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();