Request C++ values from Javascript

105 views
Skip to first unread message

Muhammed İkbal Akpaça

unread,
Nov 24, 2012, 3:23:38 PM11/24/12
to berk...@googlegroups.com
Hi,

Is there a way to get C++ values from javascript?

i made this to get my translated string

    Translate("HELLO WORLD!");
    var func = function()
    {
      count++;
      if(TranslatedString !== undefined)
      {
        ShowMessage(TranslatedString , 'green', 0);
        TranslatedString = undefined;
        clearInterval(func);
      }

      if(count > 10)
        clearInterval(func);
    };
    var count = 0;
    setInterval(func, 1);

works nicely. But I wonder if there is a more legit way of doing this.
what is void* replyMsg? I am scared of using it :D

Thank you

Ewen Cheslack-Postava

unread,
Nov 24, 2012, 3:43:06 PM11/24/12
to berk...@googlegroups.com
replyMsg is just an opaque handle for the javascript call that Chromium uses to identify it. Since it's a Chromium pointer value, we cast it to a void* so we don't have to expose that type via the Berkelium interface. We should probably just typedef it to something with a nicer name so it doesn't look so bad :)

See the glut_util handler for onJavascriptCallback for how to return values: https://github.com/sirikata/berkelium/blob/chromium11/demo/glut_util/glut_util.hpp#L518

Also, this thread was just revived a couple of days ago to get clarification on how this works, and also has an example page that works with the glut_input demo to make calls into C++ and use the return values in the javascript in the page: https://groups.google.com/forum/?fromgroups=#!topic/berkelium/lw87R6aA-cc

-Ewen

mikbal

unread,
Nov 24, 2012, 4:12:35 PM11/24/12
to berk...@googlegroups.com
Thank you for your fast answer :)

But, it crashes with null pointer access.

i used it as you showed it in glutinput
// bind
bindCallback("Translate", "Translate", true);

// callback
if(replyMsg )
win->synchronousScriptReturn(replyMsg, Script::Variant());

I dont have a debug build of berkelium to step in.

Was there a known bug that is fixed? I am using a version from January.

Ewen Cheslack-Postava

unread,
Nov 24, 2012, 4:38:38 PM11/24/12
to berk...@googlegroups.com
I can't speak to issues with the windows build since I don't use it. It could just be that null values are not handled properly, which is what Script::Variant() gives you. Try with just a string or number maybe?

-Ewen

mikbal

unread,
Nov 24, 2012, 5:39:02 PM11/24/12
to berk...@googlegroups.com
i have simplified the test application to a its most basic form. still
crashes at

if(replyMsg && numArgs > 0))
win->synchronousScriptReturn(replyMsg, args[0]);

occurs both in debug and release.
i think my build is broken. downloaded old built glut_input.exe from
downloads, tested with my html. and it works.

i don't have the resources to rebuilt berkelium, dont have a fast
internet to download chromium.

i will sent values asynchronously for now. thank god javascript is such
a flexible language.
if any one has a recent visual studio built i would like to test it.

Thanks.

Reply all
Reply to author
Forward
0 new messages