comparison Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts @ 500:329f229c2794 bgo-commands-codegen

Improvements to the integrated demo for TS <--> C++
author bgo-osimis
date Mon, 25 Feb 2019 06:35:21 +0100
parents baa9e1e932db
children 7105a0bad250
comparison
equal deleted inserted replaced
499:baa9e1e932db 500:329f229c2794
46 /* 46 /*
47 +--------------------------------------------------+ 47 +--------------------------------------------------+
48 | define stock messages | 48 | define stock messages |
49 +--------------------------------------------------+ 49 +--------------------------------------------------+
50 */ 50 */
51 let schemaText: string = `rootName: testWasmIntegratedCpp
52
53 struct B:
54 someAs: vector<A>
55 someInts: vector<int32>
56
57 struct C:
58 someBs: vector<B>
59 ddd: vector<string>
60
61 struct A:
62 someStrings: vector<string>
63 someInts2: vector<int32>
64 movies: vector<MovieType>
65
66 struct Message1:
67 a: int32
68 b: string
69 c: EnumMonth0
70 d: bool
71
72 struct Message2:
73 toto: string
74 tata: vector<Message1>
75 tutu: vector<string>
76 titi: map<string, string>
77 lulu: map<string, Message1>
78 movieType: MovieType
79
80 enum MovieType:
81 - RomCom
82 - Horror
83 - ScienceFiction
84 - Vegetables
85
86 enum CrispType:
87 - SaltAndPepper
88 - CreamAndChives
89 - Paprika
90 - Barbecue
91
92 enum EnumMonth0:
93 - January
94 - February
95 - March
96 `;
97
51 let stockSerializedMessages = new Map<string,string>(); 98 let stockSerializedMessages = new Map<string,string>();
52 stockSerializedMessages["Test 1"] = `{ 99 stockSerializedMessages["Test 1"] = `{
53 "type" : "testWasmIntegratedCpp.Message2", 100 "type" : "testWasmIntegratedCpp.Message2",
54 "value" : 101 "value" :
55 { 102 {
96 "Mercadet", 143 "Mercadet",
97 "Poisson" 144 "Poisson"
98 ] 145 ]
99 } 146 }
100 }`; 147 }`;
101 stockSerializedMessages["Test 2"] = "Test 2 stock message bccbbbbbb"; 148 stockSerializedMessages["Test 2"] = ` {
149 "type" : "testWasmIntegratedCpp.Message1",
150 "value" : {
151 "a" : -987,
152 "b" : "Salomé",
153 "c" : 2,
154 "d" : true
155 }
156 }`;
102 stockSerializedMessages["Test 3"] = "Test 3 stock message sdfsfsdfsdf"; 157 stockSerializedMessages["Test 3"] = "Test 3 stock message sdfsfsdfsdf";
103 stockSerializedMessages["Test 4"] = "Test 4 stock message 355345345"; 158 stockSerializedMessages["Test 4"] = "Test 4 stock message 355345345";
104 stockSerializedMessages["Test 5"] = "Test 5 stock message 34535"; 159 stockSerializedMessages["Test 5"] = "Test 5 stock message 34535";
105 stockSerializedMessages["Test 6"] = "Test 6 stock message xcvcxvx"; 160 stockSerializedMessages["Test 6"] = "Test 6 stock message xcvcxvx";
106 stockSerializedMessages["Test 7"] = "Test 7 stock message fgwqewqdgg"; 161 stockSerializedMessages["Test 7"] = "Test 7 stock message fgwqewqdgg";
132 return e.value; 187 return e.value;
133 } 188 }
134 189
135 function SendFreeTextFromCpp(txt: string):string 190 function SendFreeTextFromCpp(txt: string):string
136 { 191 {
137 setCppOutputValue(getCppOutputValue() + txt); 192 setCppOutputValue(getCppOutputValue() + "\n" + txt);
138 return ""; 193 return "";
139 } 194 }
140 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp; 195 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp;
141 196
142 197
148 { 203 {
149 let serializedInputValue:string = getSerializedInputValue(); 204 let serializedInputValue:string = getSerializedInputValue();
150 205
151 let SendMessageToCppLocal = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']); 206 let SendMessageToCppLocal = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']);
152 SendMessageToCppLocal(serializedInputValue); 207 SendMessageToCppLocal(serializedInputValue);
208 }
209 else if(buttonName == 'Clear')
210 {
211 setCppOutputValue("");
212 }
213 else if(buttonName == 'ShowSchema')
214 {
215 setCppOutputValue(schemaText);
216 }
217 else
218 {
219 throw new Error("Internal error!");
153 } 220 }
154 } 221 }
155 222
156 223
157 224