Hi JJ,

Well, I tried to create a wrapper object just as an experiment like this:

var jsdb = {
id : 123,
open : function() {
console.log("opening db");

and access it via emscripten::val like:

jsdb = emscripten::val::global("jsdb");

where jsdb is a private member variable of the c++ class. In that case I 
get a compile time error saying "call to deleted constructor of 
'emscripten::val' ". What am I doing wrong here?

If I just work it around by using a local variable like:

emscripten::val jsdb = emscripten::val::global("jsdb");

it works, but then any of the two lines fail during runtime:


which fails with "cannot read property 'open' of undefined"

or if I try:

emscripten::val jsdbobj = jsdb.new_();

then it fails with "constructor is not a function".

Any hint is welcome:)


2016. október 10., hétfő 20:24:35 UTC+2 időpontban jj a következőt írta:
> These types of activities are best done directly in JS side, with e.g. a 
> --js-library myMongoLibrary.js integration, rather than attempting to adapt 
> each JS code line to be called from C++ (in a JNI-style fashion). The JS 
> libraries allow storing both state and functions on JS side, which makes it 
> easier to store database objects and other things that don't need to be 
> marshalled over to C++ side, but can be pointed to via using some kind of 
> custom opaque handle. See the Emscripten src/library_xxx.js files for 
> example usage, they use this facility.
> 2016-10-10 17:24 GMT+03:00 <r0l...@freemail.hu <javascript:>>:
>> Hi All,
>> I'm trying to instantiate a mongodb client and open it via 
>> emscripten::val but I'm already stuck at the beginning:( What I'm trying 
>> achieve first, is step 3 of this mongodb doc: 
>> https://docs.mongodb.com/getting-started/node/client/ which is this js 
>> oneliner: "var MongoClient = require('mongodb').MongoClient;"
>> In the consturctor of my c++ class I have:
>> js_db::js_db(){
>> emscripten::val require = emscripten::val::global("require");
>> emscripten::val mongoModule = require(std::string("mongodb"));
>> emscripten::val mongoClient = mongoModule.MongoClient();
>> //TODO: register objIDs in global objectTracker table;
>> }
>> The error I get is: "no member named 'MongoClient' in 'emscripten::val' 
>> ". What am I doing wrong? Why don't I get it in case of mongoModule?
>> What I'd like to achieve then, based on this earlier suggestion of this 
>> group ( 
>> https://groups.google.com/d/msg/emscripten-discuss/7-i5pRK7edQ/-MrCNVAuCAAJ 
>> ) is to call mongoClient.connect() like:
>> void js_db::open(const std::string& db_uri){
>> this->db_uri=db_uri;
>> EM_ASM_({
>> var db_uri = Module.Pointer_stringify($0);
>> var mongoClient = objectTracker[$1];
>> //TODO: MongoClient.connect(db_uri, function(err, db)
>> },db_uri.c_str(),mongoClientObjId);
>> }
>> Thanks for any help in advance!
>> Best regards,
>> r0ller

You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to