分类:
2008-04-16 11:00:32
#include "jsapi.h" /*全局对象的类*/ static JSClass global_class= { "global", JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, JSCLASS_NO_OPTIONAL_MEMBERS }; int main(int argc, const char*argv[]) { /*JS 变量*/ JSRuntime *rt; JSContext *cx; JSObject *global; . . . /*创建一个JS runtime*/ rt = JS_NewRuntime(8L*1024L*1024L); if(rt == NULL) return 1; /*创建一个context*/ cx = JS_NewContext(rt, 8192); if(cx == NULL) return 1; JS_SetOption(cx, JSOPTION_VAROBJFIX); /*创建Global object*/ global = JS_NewObject(cx, &global_class, NULL, NULL); if(global == NULL) return 1; /*Populate the global object with the standard globals, like Object and Array*/ if(!JS_InitStandardClasses(cx,global)) return 1; . . . /*你应用程序的代码,可能包含JSAPI调用来创建自己的用户JS对象并且运行脚本*/ . . . /*清除*/ JS_DestroyContext(cx); JS_DestroyRuntime(rt); JS_ShutDown(); return 0; } |