charto / nbind

:sparkles: Magical headers that make your C++ library accessible from JavaScript :rocket:
MIT License
1.98k stars 119 forks source link

Is there any way to call javascript method from c++ #127

Open cvinodhkumar77 opened 5 years ago

cvinodhkumar77 commented 5 years ago

Is there any way to call a function from c++. The control should go as below: This is for a scanner device js: function jsMethod1(){ calls c++ MethodA(); } function jsMethod2(){ // some stuff }

c++: MethodA(){ // This will initialize the device }

//This will be called whenever Barcode scanned MethodB{ //should call jsMethod2 }

The reason why I'm not calling the MethodB directly is, this call will be triggered automatically by the library and there are 4 methods that are triggered similar way by the library. So basically I want to trigger a call from c++ whenever barcode scan happens which I want to sense from the js

Thanks

wzhouwzhou commented 5 years ago

Hello,

This link contains an example of calling JS functions from C++; if you're in search of class-based instance methods, then perhaps reading this section of the readme might help. Judging by the repository statistics, amount of open issues, and general rule of thumb, expecting spoonfeed from the repository maintainers does not seem to me reasonable, so at the very least the readme is easy to follow, the documentation is extensive, and the examples are nice.

William