7,802
edits
Line 92: | Line 92: | ||
# convert outputed ''string'' to ''char *'' | # convert outputed ''string'' to ''char *'' | ||
# return the actual data. Most of the time, we only have one return variable. Use that as return type for the wrapper. It's easier and cleaner from the JS perspective. | # return the actual data. Most of the time, we only have one return variable. Use that as return type for the wrapper. It's easier and cleaner from the JS perspective. | ||
# if you need to return multiple values, use a struct [http://kiwix.svn.sourceforge.net/viewvc/kiwix/moulinkiwix/src/contentManager/ContentManagerWrapper.h?revision=HEAD&view=markup example] | |||
Header example | Header example | ||
Line 148: | Line 149: | ||
I'm not very proud of it, a lot of stuff are hard coded and while it gets a ZIM as argument, it expects the swahili zim to test everything. | I'm not very proud of it, a lot of stuff are hard coded and while it gets a ZIM as argument, it expects the swahili zim to test everything. | ||
=== Write a JS module interfacing with js-ctypes and the C wrapper === | |||
Creating a JS module is not required but it's cleaner and convenient: ctypes calls requires the pointer as first argument and the return value of the calls is specific to ctypes. | |||
Our module will use js-ctypes abstract the C librar so that the whole js-ctypes is hidden. | |||
* JS module [http://kiwix.svn.sourceforge.net/viewvc/kiwix/moulinkiwix/kiwix/chrome/modules/libzimAccessor.jsm?revision=HEAD&view=markup example] | |||
Documentation: | |||
* [https://wiki.mozilla.org/JSctypes js-ctypes intro] | |||
* [https://developer.mozilla.org/en/JavaScript_code_modules/ctypes.jsm MDN page] | |||
* [https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference js-ctypes reference] | |||
* [https://wiki.mozilla.org/Jsctypes/api API on the wiki] | |||
* [https://developer.mozilla.org/en/js-ctypes/Using_js-ctypes a tutotial] | |||
* [http://blog.mozilla.com/dwitte/2010/03/12/extension-authors-browser-hackers-meet-js-ctypes/ example with struct] | |||
Rules: | |||
# Open library and declare functions in register method. | |||
# you need to declare every function of the C API. | |||
# ''char *'' returned by API are available via ''.readString()'' | |||
# ''int'' and ''bool'' returned are available via ''contents'' (raw). | |||
# [https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference/Library#declare() declare()] method gets name, abi (we use default so that it's multiplatform), return type (you need to choose this), then parameter (first one is our pointer to the class). | |||
# retrieving values from a struct [http://blog.mozilla.com/dwitte/2010/03/12/extension-authors-browser-hackers-meet-js-ctypes/ example] | |||
# Change case on method names to differentiate with original API. | |||
== Tips == | == Tips == | ||
* .so libs in xulrunner folder | * .so libs in xulrunner folder | ||
* jsm are compiled and cache at registration. You need to remove cache (or whole profile) after changes. | |||
== Remaining work == | == Remaining work == | ||
Line 157: | Line 182: | ||
* unicode | * unicode | ||
* makefiles | * makefiles | ||
* Replace XR with FF | |||
* Compatibility with XR 1.9.2? |
edits