annotate Deprecated/Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts @ 1442:11f291ac3ef5 legacy-loader-refactoring

This branch is useless.
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 26 May 2020 10:11:49 +0200
parents f6a2d46d2b76
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
1 var SendMessageToCpp: Function = null;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
2 export var TestWasmIntegratedModule : any;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
3
690
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
4 import * as TestStoneCodeGen from './build-wasm/TestStoneCodeGen_generated'
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
5
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
6 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
7 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
8 | install emscripten handlers |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
9 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
10 */
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
11
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
12 // (<any> window).Module = {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
13 // preRun: [
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
14 // function() {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
15 // console.log('Loading the Stone Framework using WebAssembly');
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
16 // }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
17 // ],
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
18 // postRun: [
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
19 // function() {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
20 // // This function is called by ".js" wrapper once the ".wasm"
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
21 // // WebAssembly module has been loaded and compiled by the
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
22 // // browser
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
23 // console.log('WebAssembly is ready');
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
24 // // window.SendMessageToCpp = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
25 // // window.SendFreeTextToCpp = (<any> window).Module.cwrap('SendFreeTextToCpp', 'string', ['string']);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
26 // }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
27 // ],
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
28 // print: function(text : string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
29 // console.log(text);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
30 // },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
31 // printErr: function(text : string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
32 // console.error(text);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
33 // },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
34 // totalDependencies: 0
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
35 // };
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
36
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
37 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
38 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
39 | install handlers |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
40 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
41 */
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
42 document.querySelectorAll(".TestWasm-button").forEach((e) => {
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
43 (e as HTMLButtonElement).addEventListener("click", () => {
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
44 ButtonClick(e.attributes["tool-selector"].value);
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
45 });
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
46 });
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
47
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
48 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
49 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
50 | define stock messages |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
51 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
52 */
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
53 let schemaText: string = null;
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
54 fetch("testTestStoneCodeGen.yaml").then(function(res) {return res.text();}).then(function(text) {schemaText = text;});
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
55
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
56 let stockSerializedMessages = new Map<string,string>();
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
57 stockSerializedMessages["Test CppHandler message2"] = null;
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
58 fetch("cppHandler_test_Message2.json").then(function(res) {return res.text();}).then(function(text) {stockSerializedMessages["Test CppHandler message2"] = text;});
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
59
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
60 stockSerializedMessages["Test 2"] = ` {
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
61 "type" : "TestStoneCodeGen.Message1",
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
62 "value" : {
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
63 "memberInt32" : -987,
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
64 "memberString" : "Salomé",
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
65 "memberEnumMonth" : "March",
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
66 "memberBool" : true,
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
67 "memberFloat32" : 0.1,
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
68 "memberFloat64" : -0.2,
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 519
diff changeset
69 "extraMember" : "don't care"
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
70 }
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
71 }`;
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
72 stockSerializedMessages["Test 3"] = "Test 3 stock message sdfsfsdfsdf";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
73 stockSerializedMessages["Test 4"] = "Test 4 stock message 355345345";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
74 stockSerializedMessages["Test 5"] = "Test 5 stock message 34535";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
75 stockSerializedMessages["Test 6"] = "Test 6 stock message xcvcxvx";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
76 stockSerializedMessages["Test 7"] = "Test 7 stock message fgwqewqdgg";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
77 stockSerializedMessages["Test 8"] = "Test 8 stock message fgfsdfsdgg";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
78
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
79 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
80 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
81 | define handler |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
82 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
83 */
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
84
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
85 function setSerializedInputValue(text: string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
86 let e : HTMLTextAreaElement = document.getElementById('TestWasm-SerializedInput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
87 e.value = text;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
88 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
89
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
90 function getSerializedInputValue(): string {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
91 let e : HTMLTextAreaElement = document.getElementById('TestWasm-SerializedInput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
92 return e.value;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
93 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
94
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
95 function setCppOutputValue(text: string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
96 let e : HTMLTextAreaElement = document.getElementById('TestWasm-CppOutput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
97 e.value = text;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
98 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
99
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
100 function getCppOutputValue(): string {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
101 let e : HTMLTextAreaElement = document.getElementById('TestWasm-CppOutput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
102 return e.value;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
103 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
104
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
105 function SendFreeTextFromCpp(txt: string):string
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
106 {
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
107 setCppOutputValue(getCppOutputValue() + "\n" + txt);
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
108 return "";
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
109 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
110 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
111
690
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
112 var referenceMessages = Array<any>();
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
113
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
114 function testTsCppTs() {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
115 var r = new TestStoneCodeGen.Message2();
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
116 r.memberEnumMovieType = TestStoneCodeGen.MovieType.RomCom;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
117 r.memberStringWithDefault = "overriden";
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
118 r.memberMapEnumFloat[TestStoneCodeGen.CrispType.CreamAndChives] = 0.5;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
119 r.memberString = "reference-messsage2-test1";
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
120
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
121 referenceMessages[r.memberString] = r;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
122 var strMsg2 = r.StoneSerialize();
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
123 let SendMessageToCppForEchoLocal = (<any> window).Module.cwrap('SendMessageToCppForEcho', 'string', ['string']);
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
124 SendMessageToCppForEchoLocal(strMsg2);
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
125 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
126
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
127 class MyEchoHandler implements TestStoneCodeGen.IHandler
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
128 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
129 public HandleMessage2(value: TestStoneCodeGen.Message2): boolean
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
130 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
131 if (value.memberString in referenceMessages) {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
132 let r = referenceMessages[value.memberString];
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
133 let equals = (value.memberStringWithDefault == r.memberStringWithDefault);
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
134 if (TestStoneCodeGen.CrispType.CreamAndChives in r.memberMapEnumFloat) {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
135 equals == equals && r.memberMapEnumFloat[TestStoneCodeGen.CrispType.CreamAndChives] == value.memberMapEnumFloat[TestStoneCodeGen.CrispType.CreamAndChives];
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
136 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
137 // TODO continue comparison
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
138
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
139 if (equals) {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
140 console.log("objects are equals after round trip");
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
141 return true;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
142 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
143 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
144 console.log("problem after round trip");
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
145 return true;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
146 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
147 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
148
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
149 function SendMessageFromCpp(txt: string):string
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
150 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
151 setCppOutputValue(getCppOutputValue() + "\n" + txt);
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
152 TestStoneCodeGen.StoneDispatchToHandler(txt, new MyEchoHandler());
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
153 return "";
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
154 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
155 (<any> window).SendMessageFromCpp = SendMessageFromCpp;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
156
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
157
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
158
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
159 function ButtonClick(buttonName: string) {
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
160 if (buttonName.startsWith('Test ')) {
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
161 setSerializedInputValue(stockSerializedMessages[buttonName]);
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
162 }
690
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
163 else if (buttonName == "Test-ts-cpp-ts") {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
164 testTsCppTs();
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 687
diff changeset
165 }
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
166 else if(buttonName == 'Trigger')
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
167 {
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
168 let serializedInputValue:string = getSerializedInputValue();
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
169
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
170 let SendMessageToCppLocal = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
171 SendMessageToCppLocal(serializedInputValue);
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
172 }
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
173 else if(buttonName == 'Clear')
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
174 {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
175 setCppOutputValue("");
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
176 }
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
177 else if(buttonName == 'ShowSchema')
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
178 {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
179 setCppOutputValue(schemaText);
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
180 }
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
181 else
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
182 {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
183 throw new Error("Internal error!");
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
184 }
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
185 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
186
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
187
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
188
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
189 // this method is called "from the C++ code" when the StoneApplication is updated.
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
190 // it can be used to update the UI of the application
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
191 function UpdateWebApplicationWithString(statusUpdateMessageString: string) {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
192 console.log("updating web application (string): ", statusUpdateMessageString);
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
193 let statusUpdateMessage = JSON.parse(statusUpdateMessageString);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
194
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
195 if ("event" in statusUpdateMessage)
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
196 {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
197 let eventName = statusUpdateMessage["event"];
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
198 if (eventName == "appStatusUpdated")
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
199 {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
200 //ui.onAppStatusUpdated(statusUpdateMessage["data"]);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
201 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
202 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
203 }
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
204
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
205
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
206 function UpdateWebApplicationWithSerializedMessage(statusUpdateMessageString: string) {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
207 console.log("updating web application (serialized message): ", statusUpdateMessageString);
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
208 console.log("<not supported!>");
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
209 }
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
210