c++ - Javascript function only works within a function (with c interface) -
i new javascript , writing api getting server status c++ code that's running underneath. understand question may (or may not) project dependent, i'm wondering if has insight of possibly wrong here.
so want call "checkserverstatuscpp()" function, implemented in c++ on "manager.cpp". (i reusing else code , need compile , interface automatically generated. attach info possible.)
i found if wrap call within function, native c++ code executed.
a = function(){ manager.getserverstatuscpp(); }; a(); // no problem calling function in manager.cpp
otherwise won't work
manager.getserverstatuscpp(); // function getserverstatuscpp() in manager.cpp never called.
here related files.
home.html
<!doctype html> <head> <!-- other js/css files in here. --> <script type="text/javascript" src="js/interface.js"></script> <script type="text/javascript" src="js/system.media.manager.js"></script> <script type="text/javascript" src="js/man.js"></script> </head> <body> <fieldset> <legend> <b> server status </b> </legend> <div class="pad10"> <p> <a onclick="refresh()" id="refresh" href="#"> refresh </a></p> </div> </fieldset> <script> var manager = new system.manager("1"); function refresh() { // works - native function called. = function(){manager.getserverstatuscpp();}; a(); // if put function in c++ not executed. manager.getserverstatuscpp(); } function ongetserverstatus(myobject) { //do }; </script> </body> </html>
man.js (i rewriting auto-generated function where)
system.manager = system.media.imanager.extend({ init : function(instance) { this._super(instance); this.count = 0; }, getserverstatuscppcallback: function( myobject ) { console.log("getserverstatuscpp-->" + json.stringify(myobject)); ongetserverstatus(myobject); }, });
system.media.manager.js (this file automatically generated)
system.media = system.media || {}; system.media.imanager = system.interface.extend({ init : function(instance) { this._super("system::imanager", instance); }, getserverstatucppscallback: function( myobject ) { console.log("getserverstatuscpp-->" + json.stringify(myobject)); }, getserverstatuscpp: function() { this.call( {"method": "imanager::getserverstatuscpp", "params":{ } }, this.getserverstatuscppcallback, []); }, }); /** * end of imanager interface */ });
note: manager.cpp, manager.h native c++ code, , imanager.h implement js interface.
any hint appreciated!
Comments
Post a Comment