libjspp
TRANSCRIPT
-
7/31/2019 libjspp
1/13
-
7/31/2019 libjspp
2/13
copyright @ anand rathi 2012
General description
Libjspp allows easy interfacing & interacting ofC++ with javascript[currently spidermonkey1.8.5]
Non intrusive to C++ & javascript world at sametime.
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 perprocess or per thread and export native
functions , class, variables. Cont...
-
7/31/2019 libjspp
3/13
copyright @ anand rathi 2012
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 & frequentsmemory allocations.
Cont...
-
7/31/2019 libjspp
4/13
copyright @ anand rathi 2012
General description
Javascript world is agnoustic about to fact thatclass / object was by C++
Exported C++ class objects is agnoustic to fact
that they are Proxy to Javascript object.
-
7/31/2019 libjspp
5/13
-
7/31/2019 libjspp
6/13
copyright @ anand rathi 2012
Example: Anonymous Object use caseC++ Code for creating object called 'MyObject'
void testfunc() { std::cout
-
7/31/2019 libjspp
7/13
copyright @ anand rathi 2012
Javascript Code using 'MyObject'
CONSOLE.writeln(MyObject.x);
CONSOLE.writeln(MyObject.y);
CONSOLE.writeln(MyObject.shx);
MyObject.shx="5432 5432 5432 5432 5432 5432 5432 5432 5432 54321 53" ;
MyObject.shx="5432 5432 5432 5432 5432 5432 5432 5432 48" ;MyObject.testfunc();
MyObject.testfunca(" test string");
MyObject.testfuncb(" test string b");
MyObject.testfuncc(1234);
MyObject.testfuncd(111.222);
CONSOLE.writeln('hello \n') ;
Cont...
-
7/31/2019 libjspp
8/13
copyright @ anand rathi 2012
Example: Export Native Class use caseC++ Code for creating object called ''
class Cc {public:
Cc(){printf("In default constructor of c \n"); }Cc(int pi) {
printf("In constructor of c %d\n",pi );
i=pi;d=3.33;s="444";
}Cc(std::string i) {printf("In constructor of c %s\n",i.c_str() );}Cc(std::string & i) {printf("In constructor of c %s\n",i.c_str() ); }char c;int i;
double d;std::string s;int sfunc(std::string& a) { std::cout ("ivar").setVariable< double, &Cc::d >("dvar").setVariable< std::string, &Cc::s >("svar");///Export Native C++ class and its properties & function
pec->registerEngine(_js);int eret = _js.CompileExecuteFile("/home/libcdr/TestJSScriptExportClass.js");
}Cont...
-
7/31/2019 libjspp
9/13
copyright @ anand rathi 2012
Javascript Code creating and using Export Native Class
//
CONSOLE.writeln('hello \n') ;var tObj = new testclass(2);tObj.sfunc("Hello JS\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') ;
-
7/31/2019 libjspp
10/13
copyright @ anand rathi 2012
Future work ..cont Export more complex class properties, function Parameter
currently only std::string, int, double are mappedexampleclass A {
std::string s;};class B {
A peropertyA};
JSEngine _js;exporterCLass *pecA = exporterCLass::GetInstance("A");
pecA->setVariable< std::string, &A::s >("s")pecA->registerEngine(_js);
exporterCLass *pecB = exporterCLass::GetInstance("B");pecB->setVariable< exporterCLass, &B::A >("peropertyA")
----------------------------------------------------------------------
In javascript
var tObj = new B();tObj.peropertyA = Hello;
-
7/31/2019 libjspp
11/13
copyright @ anand rathi 2012
... Future work
Adding capablity to Invoke Javascript functionfrom C++
Adding capablity to acess Javascript properties
from C++ Javascript as Inversion of control
Upto 10 or more parameters in functions &
constructors Modules to wrap various other C/C++ libraries
database , http server, curl and more goodies
-
7/31/2019 libjspp
12/13
-
7/31/2019 libjspp
13/13