Libjspp
Libjspp
Anand Rathi
General description
Libjspp allows easy interfacing & interacting of C++ with javascript[currently spidermonkey 1.8.5] Non intrusive to C++ & javascript world at same time. Useful for applications who want to Embed & Extend in Object oriented manner. Very thin interface, By using C++ templates. App can create multiple javascript engines per process or per thread and export native copyright @ anand rathi 2012 functions , class, variables. Cont...
General description
Multi threaded support for each engine per thread. Dynamically define Cached & Non Cached property. Caching of properties defined in native & anonymous object allow direct local acess without need of conversions. Caching of strings avoids trivial & frequents memory allocations.
Cont...
copyright @ anand rathi 2012
General description
Javascript world is agnoustic about to fact that class / object was by C++ Exported C++ class objects is agnoustic to fact that they are Proxy to Javascript object.
Use Cases
1) Anonymous Object: Creating named Non C++ objects inside Javascript engine from C++ dynamically & defining properties and attaching native C++ methods as functions of that object. 2) Export Native Class: Exporting existing C++ class as javascript class which includes exposing
Exposing native constructor [currently only One] Exposing native methods Exposing native properties User can create as many instances these ProxyObjects
copyright @ anand rathi 2012
C++Codeforcreatingobjectcalled'MyObject' voidtestfunc(){ std::cout<<"testfunc\n";} voidtestfunca(std::stringa){std::cout<<"testfunca="<<a<<"\n";} voidtestfuncb(std::string&a){ std::cout<<"testfunca="<<a<<"\n";} voidtestfuncc(int&a){ std::cout<<"testfunca="<<a<<"\n";} voidtestfuncd(double&a){ std::cout<<"testfunca="<<a<<"\n";} TestAnonymous(){ ///Create newJavascriptEngine JSEngine_js; intiret=_js.Init(); if(iret!=0){printf("initfailed\n");} defConsole(_js); ///Create newAnonymousObjectMyObjectaspropertyofglobalobject AnonymousJSObject*pdj=newAnonymousJSObject("MyObject",_js); std::stringsval="12346"; ///Create newAnonymousObjectMyObjectaspropertyofglobalobject pdj>SetPropertyVal("x","1234",false,false); pdj>SetPropertyVal("y","4321",false,false); ///Define New Externel PropertiesExternelpropertiesarecachedvariables. pdj>DefPropertyValExternalString("shx",sval); pdj>SetPropertyValExternalString("shx","1234123412341234123412341234 123412341234513"); ///Define new functions and add them to the 'MyObject' pdj>addFunc<testfunc>("testfunc",testfunc); pdj>addFunc<void,std::string,testfunca>("testfunca",testfunca); pdj>addFunc<void,std::string&,testfuncb>("testfuncb",testfuncb); pdj>addFunc<void,int&,testfuncc>("testfuncc",testfuncc); pdj>addFunc<void,double&,testfuncd>("testfuncd",testfuncd); ///Compile and execute script in the test.js file' interet=_js.CompileExecuteFile("/home/libjss/test.js"); }Cont... copyright @ anand rathi 2012
JavascriptCodeusing'MyObject' CONSOLE.writeln(MyObject.x); CONSOLE.writeln(MyObject.y); CONSOLE.writeln(MyObject.shx); MyObject.shx="5432543254325432543254325432543254325432153"; MyObject.shx="5432543254325432543254325432543248"; MyObject.testfunc(); MyObject.testfunca("teststring"); MyObject.testfuncb("teststringb"); MyObject.testfuncc(1234); MyObject.testfuncd(111.222); CONSOLE.writeln('hello\n'); Cont...
JavascriptCodecreatingandusingExportNativeClass // CONSOLE.writeln('hello\n'); vartObj=newtestclass(2); tObj.sfunc("HelloJS\n") CONSOLE.write('tObj.ivar='); CONSOLE.writeln(tObj.ivar); CONSOLE.write('tObj.dvar='); CONSOLE.writeln(tObj.dvar); CONSOLE.write('tObj.svar='); CONSOLE.writeln(tObj.svar); CONSOLE.writeln('done\n');
Contact
[email protected] http://netya.weebly.com/contact.html