Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support native modules #291

Closed
slavchev opened this issue Dec 1, 2015 · 5 comments
Closed

Support native modules #291

slavchev opened this issue Dec 1, 2015 · 5 comments
Assignees
Milestone

Comments

@slavchev
Copy link

slavchev commented Dec 1, 2015

Provide support for native modules similar to Node.js addons. Regular JavaScript modules are loaded as follows

var myModule = require('./myModule.js');

Similarly, we can load native module as follows

var myModule = require('./libMyModule.so');

Native modules provide glue to C and C++ libraries. They are useful in performance sensitive scenarios because they avoid JavaScript-to-Java marshalling. Good examples are OpenGL libraries.

You can find sample implementation of native module here.

@x4080
Copy link

x4080 commented May 20, 2016

hi, I wondered how to call the sample code in JavaScript? after the require?

and how to provide different so for different architecture?

@slavchev
Copy link
Author

There is a small example in this commit. Take a look at bece3ae#diff-c273f07649566e409bd510c972c40aa5R20

@x4080
Copy link

x4080 commented May 21, 2016

thanks for the tip, is this technique can only call nsmain? or we can call any function using Java call to jni?

@slavchev
Copy link
Author

is this technique can only call nsmain?

Yes. {N} for Android does not provide means to for loading general purpose shared libraries. We look for NSMain export and call it. In my previous comment I showed you how to call add function. You can think of NSMain like a place to initialize your module. See how we export add function https://github.com/NativeScript/sample-native-module/blob/932235bfe818d4be025a747325b8d924c7310f6c/Android/CalcLib/jni/Calc.cpp#L35-L36

or we can call any function using Java call to jni

Currently {N} for Android doesn't provide such functionality. While implementing this functionality is technically possible (and relatively easy to implement), we haven't came across such scenario yet. If there is interest in it then we can add it to our task list.

@x4080
Copy link

x4080 commented May 25, 2016

OK I understand now. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants