Download the file in webAssembly virtual memory.

     $('screen_shot').onclick = function()
     {
        var fileName = workerObj.GetScreenShot();


        console.log( "fileName: ", fileName );  
        const shot =  Module.FS.readFile( fileName );
        const link = document.createElement('a');
        link.style.display = 'none';
        document.body.appendChild(link);
        const blob = new Blob([shot]);
        link.href = URL.createObjectURL(blob);
        link.download = 'shot.png';
        link.click();
        document.body.removeChild(link);
     }

Initialize wasm module object asynchronously.

var worker;
Module = {};
Module.onRuntimeInitialized = function() { //async init
	worker = new Module.UWorker();
	console.log( "worker: ", worker );
}
workModule(Module); // start with Glue layer code

Export C++ enum value to JS

#include <emscripten/bind.h>
#include "UWorker.h"

using namespace emscripten;

EMSCRIPTEN_BINDINGS(UWorker) {
    class_<UWorker>("UWorker")
        .constructor()
        .function("ComputeNums", &UWorker::ComputeNums)
        ;

    enum_<UWorker::ComputeType>("ComputeType")
    .value("E_Add", UWorker::ComputeType::E_Add)
    .value("E_Sub", UWorker::ComputeType::E_Sub)
    .value("E_Multiply", UWorker::ComputeType::E_Multiply)
    .value("E_Divide", UWorker::ComputeType::E_Divide)
    .value("E_Pow", UWorker::ComputeType::E_Pow)
    .value("E_Mod", UWorker::ComputeType::E_Mod)
    ;
}

Use the enum value in javascript code.

if( targetFormat === "+" )
{
    result = worker.ComputeNums( str1, str2, Module.ComputeType.E_Add );
}
Categories: Web

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x