Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Emscripten how to pass variables from JavaScript to oF?

$
0
0

Thank you for your reply @arturo
I had a look at the ofxEmscripten video player but I am still unsure how it works.
Without success I tried to to create a text box in the html page and read the value in the oF app, I tried to use similar structure and model as the video player and did the following

created a file
library_html5com.js

var LibraryHTML5Com = {
$COM: {

getJavaString: function(){
    var ret = document.getElementById('stringJava')
    return ret;
}

}

autoAddDeps(LibraryHTML5Com, '$COM');
mergeInto(LibraryManager.library, LibraryHTML5Com);

created a file
html5com.h

pragma once

extern "C"{

extern std::string getJavaString();

}

created ofxEmscriptenCom.h

pragma once
include string

class ofxEmscriptenCom {
public:

ofxEmscriptenCom();
~ofxEmscriptenCom();

std::string getJavaString();

};

ofxEmscriptenCom.cpp

include "ofxEmscriptenCom.h"
include "html5com.h"

ofxEmscriptenCom::ofxEmscriptenCom(){}
ofxEmscriptenCom::~ofxEmscriptenCom(){}

std::string ofxEmscriptenCom::getJavaString(){

return getJavaString();

}

I have included ofxEmscripten addons to my project and in ofApp.cpp update() I have

ofxEmscriptenCom com;
string javaString = com.getJavastring();

Finally in the myApp.html generated from "emmake make" I have added

input type='text' id='stringJava' />
input type='button' onclick='notEmpty()' value='Form Checker' />


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>