Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/stone-framework-loader.ts @ 419:d638d5721f1c
replace deprecated writeStringToMemory by stringToUTF8
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Nov 2018 18:41:50 +0100 |
parents | 126c9c0c9333 |
children | 5055031f4a06 |
rev | line source |
---|---|
223 | 1 module Stone { |
2 /** | |
3 * This file contains primitives to interface with WebAssembly and | |
4 * with the Stone framework. | |
5 **/ | |
6 | |
7 export declare type InitializationCallback = () => void; | |
8 | |
9 export declare var StoneFrameworkModule : any; | |
10 | |
11 //const ASSETS_FOLDER : string = "assets/lib"; | |
12 //const WASM_FILENAME : string = "orthanc-framework"; | |
13 | |
14 | |
15 export class Framework | |
16 { | |
17 private static singleton_ : Framework = null; | |
238
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
18 private static wasmModuleName_ : string = null; |
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
19 |
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
20 public static Configure(wasmModuleName: string) { |
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
21 this.wasmModuleName_ = wasmModuleName; |
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
22 } |
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
23 |
223 | 24 private constructor(verbose : boolean) |
25 { | |
26 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]); | |
27 } | |
28 | |
29 | |
30 public ccall(name: string, | |
31 returnType: string, | |
32 argTypes: Array<string>, | |
33 argValues: Array<any>) : any | |
34 { | |
35 return StoneFrameworkModule.ccall(name, returnType, argTypes, argValues); | |
36 } | |
37 | |
38 | |
39 public cwrap(name: string, | |
40 returnType: string, | |
41 argTypes: Array<string>) : any | |
42 { | |
43 return StoneFrameworkModule.cwrap(name, returnType, argTypes); | |
44 } | |
45 | |
46 | |
47 public static GetInstance() : Framework | |
48 { | |
49 if (Framework.singleton_ == null) { | |
50 throw new Error('The WebAssembly module is not loaded yet'); | |
51 } else { | |
52 return Framework.singleton_; | |
53 } | |
54 } | |
55 | |
56 | |
57 public static Initialize(verbose: boolean, | |
58 callback: InitializationCallback) | |
59 { | |
238
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
60 console.log('Initializing WebAssembly Module'); |
223 | 61 |
62 (<any> window).StoneFrameworkModule = { | |
63 preRun: [ | |
64 function() { | |
65 console.log('Loading the Stone Framework using WebAssembly'); | |
66 } | |
67 ], | |
68 postRun: [ | |
69 function() { | |
70 // This function is called by ".js" wrapper once the ".wasm" | |
71 // WebAssembly module has been loaded and compiled by the | |
72 // browser | |
73 console.log('WebAssembly is ready'); | |
74 Framework.singleton_ = new Framework(verbose); | |
75 callback(); | |
76 } | |
77 ], | |
78 print: function(text : string) { | |
79 console.log(text); | |
80 }, | |
81 printErr: function(text : string) { | |
82 console.error(text); | |
83 }, | |
84 totalDependencies: 0 | |
85 }; | |
86 | |
87 // Dynamic loading of the JavaScript wrapper around WebAssembly | |
88 var script = document.createElement('script'); | |
89 script.type = 'application/javascript'; | |
237
b4642964c355
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
236
diff
changeset
|
90 //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
238
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
91 script.src = this.wasmModuleName_ + ".js";// "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
223 | 92 script.async = true; |
93 document.head.appendChild(script); | |
94 } | |
95 } | |
96 } |