Search code examples
javascriptfirebreath

Firebreath - passing parameter in callback function


I have a code where from javascript i am passing a function

exportManager.RegisterCallbacks(function(progress) {
                                console.log("export prog " + progress);
                             }, function() {
                                console.log("Export Done");
                             }, function() {
                                console.log("Export Error");
                             }, function() {
                                console.log("Export Abort");
                             });

and in the plugin

m_currentExportProgress += progress;
int prog = (m_currentExportProgress.load() / m_totalProgress) * 100;

m_onProgress->InvokeAsync("", FB::variant_list_of(shared_from_this())(prog));

however when i write the result, i get

 export prog <JSAPI-Auto Javascript Object>

Solution

  • Yes, your code is working exactly as it is set to do. You are passing two parameters into the callback: first, a reference to your JSAPI instance shared_from_this() and second prog.

    If you want to pass only one parameter, only provide one parameter:

    m_onProgress->InvokeAsync("", FB::variant_list_of(prog));