CPJ is not in reality pure programming language, but rather subset of CPlusPlus and JavaScript. It permits to produce code which can be use directly in both cases, without any modification. Of course some part of code will be in any case language depending, particlurary Input/Output, User Interface etc.
Variables.
It recommended (but not limited) to use only simple types as integer, real and strings. Any other type can be replaced by. Declaration looks like :
var intvar i,j,k;var doublevar a,b;
In CPP, of course, you have to add line
#define var
JS do not support variable types , it is recommended(when it nessesary) to use for casting functions/macros, which can look as following :
function ToInt(A){return A|0;} #define ToInt(A) ((int)(A))
Typically the place where it must be applyed is math operations with integers (for example i=j/10 may yield different values in CPP and JS). It is nessesary be carrefull with array indexes, one of the area of integer using.
String in CPP must be handled by some class like CString in Visual Studio, constant LPCSTR can be used too.
var CStringvar Text="ABC";
Functions.
There is specific way to declare function in CPP. 3 files have to be used as exampled :
First H file#define function#define Do(Mode) void Do(int Mode)#define Make(Mode, Style) void MakeA(int Mode, int Style)
Second CPJ file ( common for CPP and JS)function Do(Mode){...}function Make(Mode, Style){...}
Third H file#undef Do#undef Make#define Make MakeA
Then you can call this function in standard way for example :
Do(3); Make(3,5);
The differences in "Do" and "Make" declaration is that you can call "Make" inside CPJ file as "MakeA" . Second function required also extra modification of JS as following :
var MakeA=Make;
To enable compilation order, files can be listed in some separate CPP file as following for example :
#inlcude H1#inlcude CPJ#inlcude H2
Arrays.
Using of dynamal size arrays can be done with implementation functions mallocarr, reallocarr, freearr, as for example :
function malloc() { return new Array();}LPBYTE mallocarr(LPBYTE Arr, int Size){return (LPBYTE)malloc(Size*sizeof(BYTE);};
It is nessarry of couse avoid manipulation with pointers, which do not supported by JS :
Arr=Arr+100;
Oher approach is to use class similar with CArray of MS Visual Studio. This is usefull (to avoid memory leak ) and increase code clearity. The implementation can be as following :
var CIntArrayvar Arr;Arr= CreateArray(Arr, 1024);
Using array wit initialization can be done in te same way
var CIntArrayvar Arr;Arr= CreateArray(Arr, 1,2,10,31,45);Extra implementation.
Usefull string and math fuction of CPP (sprintf, strchr, strstr, cos,sin etc) can be implemented in JS in near one line way.