Skip to content

How are bindings to existing native frameworks generated?

florianf edited this page Sep 25, 2016 · 8 revisions

##RoboPods If your looking for a binding to a popular 3rd party library, it maybe already be done by the RoboPod project. For a list of current supported libraries take a look at: https://github.com/MobiDevelop/robovm-robopods/issues/1

##bro-gen bro-gen is a Ruby script that generates RoboVM bindings semi-automatically. You need to write a YAML mapping file for the library to generate the binding. For details head over to CoderBaron's fork of bro-gen which works with the current RoboVM version https://github.com/CoderBaron/robovm-bro-gen

For some examples of YAML mapping files take a look at the config files for the iOS Cocoatouch or UIKit bindings in this repository https://github.com/MobiDevelop/robovm/tree/master/compiler/cocoatouch/src/main/bro-gen Those mappings are automatically generated with CoderBaron's bro-gen fork.

##Create bindings manually For small to medium sized libraries it maybe feasible to write the bindings manually. For a simple example binding take a look at the bindings to the SVGgh library https://github.com/florianf/robopod-ghs-svg.

The original RoboVM documentation has a nice introduction to the binding mechanism used by RoboVm http://docs.robovm.com/advanced-topics/bro.html

##Tips & Tricks

  • CGRect and CGSize method parameters should always be annotated with the @ByVal annotation.
  • Bro doesn't support float, always use a double annotated with @MachineSizedFloat

###Simple example

@Method(selector = "asImageWithSize:andScale:")
public native UIImage asImageWithSize(@ByVal CGSize maximumSize, @MachineSizedFloat double scale);