diff Platforms/Wasm/stone-framework-loader.ts @ 466:5055031f4a06 bgo-commands-codegen

- Added browserify to build. This allows using require calls for modules that work with tsc compiler. - removed older stuff related to Protocol Buffers and Flatbuffers - changed triple-slash references to import statements - module prefixes are now added at call sites - added cmake module for filename handling - switched to Ninja for sample build - Added virtual dtor in ICommand
author bgo-osimis
date Mon, 11 Feb 2019 16:00:04 +0100
parents 126c9c0c9333
children 548eed46f535
line wrap: on
line diff
--- a/Platforms/Wasm/stone-framework-loader.ts	Wed Jan 16 21:08:38 2019 +0100
+++ b/Platforms/Wasm/stone-framework-loader.ts	Mon Feb 11 16:00:04 2019 +0100
@@ -1,96 +1,95 @@
-module Stone {
-    /**
-     * This file contains primitives to interface with WebAssembly and
-     * with the Stone framework.
-     **/
-    
-    export declare type InitializationCallback = () => void;
-    
-    export declare var StoneFrameworkModule : any;
-    
-    //const ASSETS_FOLDER : string = "assets/lib";
-    //const WASM_FILENAME : string = "orthanc-framework";
-    
-    
-    export class Framework
-    {
-      private static singleton_ : Framework = null;
-      private static wasmModuleName_ : string = null;
+/**
+ * This file contains primitives to interface with WebAssembly and
+ * with the Stone framework.
+ **/
+
+export declare type InitializationCallback = () => void;
+
+//export declare var StoneFrameworkModule : any;
+export var StoneFrameworkModule : any;
+
+//const ASSETS_FOLDER : string = "assets/lib";
+//const WASM_FILENAME : string = "orthanc-framework";
+
+export class Framework
+{
+  private static singleton_ : Framework = null;
+  private static wasmModuleName_ : string = null;
+
+  public static Configure(wasmModuleName: string) {
+    this.wasmModuleName_ = wasmModuleName;
+  }
 
-      public static Configure(wasmModuleName: string) {
-        this.wasmModuleName_ = wasmModuleName;
-      }
+  private constructor(verbose : boolean) 
+  {
+    //this.ccall('Initialize', null, [ 'number' ], [ verbose ]);
+  }
+
+  
+  public ccall( name: string,
+                returnType: string,
+                argTypes: Array<string>,
+                argValues: Array<any>) : any
+  {
+    return (<any> window).StoneFrameworkModule.ccall(name, returnType, argTypes, argValues);
+  }
+
+  
+  public cwrap( name: string,
+                returnType: string,
+                argTypes: Array<string>) : any
+  {
+    return (<any> window).StoneFrameworkModule.cwrap(name, returnType, argTypes);
+  }
 
-      private constructor(verbose : boolean) 
-      {
-        //this.ccall('Initialize', null, [ 'number' ], [ verbose ]);
-      }
-    
-      
-      public ccall(name: string,
-                   returnType: string,
-                   argTypes: Array<string>,
-                   argValues: Array<any>) : any
-      {
-        return StoneFrameworkModule.ccall(name, returnType, argTypes, argValues);
-      }
-    
-      
-      public cwrap(name: string,
-                   returnType: string,
-                   argTypes: Array<string>) : any
-      {
-        return StoneFrameworkModule.cwrap(name, returnType, argTypes);
-      }
-    
-      
-      public static GetInstance() : Framework
-      {
-        if (Framework.singleton_ == null) {
-          throw new Error('The WebAssembly module is not loaded yet');
-        } else {
-          return Framework.singleton_;
+  
+  public static GetInstance() : Framework
+  {
+    if (Framework.singleton_ == null) {
+      throw new Error('The WebAssembly module is not loaded yet');
+    } else {
+      return Framework.singleton_;
+    }
+  }
+
+
+  public static Initialize( verbose: boolean,
+                            callback: InitializationCallback)
+  {
+    console.log('Initializing WebAssembly Module');
+
+    // (<any> window).
+    (<any> window).StoneFrameworkModule = {
+      preRun: [ 
+        function() {
+          console.log('Loading the Stone Framework using WebAssembly');
         }
-      }
-      
-    
-      public static Initialize(verbose: boolean,
-                               callback: InitializationCallback)
-      {
-        console.log('Initializing WebAssembly Module');
-    
-        (<any> window).StoneFrameworkModule = {
-          preRun: [ 
-            function() {
-              console.log('Loading the Stone Framework using WebAssembly');
-            }
-          ],
-          postRun: [ 
-            function()  {
-              // This function is called by ".js" wrapper once the ".wasm"
-              // WebAssembly module has been loaded and compiled by the
-              // browser
-              console.log('WebAssembly is ready');
-              Framework.singleton_ = new Framework(verbose);
-              callback();
-            }
-          ],
-          print: function(text : string) {
-            console.log(text);
-          },
-          printErr: function(text : string) {
-            console.error(text);
-          },
-          totalDependencies: 0
-        };
-    
-        // Dynamic loading of the JavaScript wrapper around WebAssembly
-        var script = document.createElement('script');
-        script.type = 'application/javascript';
-        //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
-        script.src = this.wasmModuleName_ + ".js";//  "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
-        script.async = true;
-        document.head.appendChild(script);
-      }
-    }
-}
\ No newline at end of file
+      ],
+      postRun: [ 
+        function()  {
+          // This function is called by ".js" wrapper once the ".wasm"
+          // WebAssembly module has been loaded and compiled by the
+          // browser
+          console.log('WebAssembly is ready');
+          Framework.singleton_ = new Framework(verbose);
+          callback();
+        }
+      ],
+      print: function(text : string) {
+        console.log(text);
+      },
+      printErr: function(text : string) {
+        console.error(text);
+      },
+      totalDependencies: 0
+    };
+
+    // Dynamic loading of the JavaScript wrapper around WebAssembly
+    var script = document.createElement('script');
+    script.type = 'application/javascript';
+    //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
+    script.src = this.wasmModuleName_ + ".js";//  "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
+    script.async = true;
+    document.head.appendChild(script);
+  }
+}