Home

Awesome

bro-gen

bro-gen tutorial - dkimitsa's dev blog

bro-gen is a Ruby script which can be used to generate RoboVM bindings for C/Objective-C libraries and frameworks.

Requirements

Getting the code.

Important: checkout both robovm-bro-gen and robovm to same root. This allows to use using cocoa-touch yaml files for iOS system frameworks.

git clone git://github.com/dkimitsa/robovm-bro-gen.git
git clone git://github.com/mobivm/robovm.git

Usage

./bro-gen path/to/put/generated/sources config1.yaml [config2.yaml ...]

YAML config file format

The YAML config files are used to tell the script how to process the functions, classes, enums, structs, etc in a particular framework or library. The supported top level keys are:

About regexps

Many of the keys in the YAML hashes are regexp patterns. A regexp must match the input fully to be a match so there's no need to use ^ and $ at the stared and end of the regexp. Capturing groups in the regexp pattern can be used in the values of the hash. These are referenced using Ruby style placeholders. #{g[0]} for the first group, #{g[1]} for the second and so on.

enums

The keys in this hash specify enum names. Only enums that have a matching key in this hash will be generated. The values are also hashes, usually empty ({}) but the following keys are supported:

classes

The keys in this hash specify class/struct name regexp patterns. Only classes/structs that have a matching key in this hash will be generated. The values are also hashes with the following supported keys:

protocols

The keys in this hash specify Objective-C protocol name regexp patterns. Only protocols that have a matching key in this hash will be generated. A Java interface will be generated for each matching protocol along with an adapter class implementing all methods in the interface.

The values are also hashes with the following supported keys:

categories

The keys in this hash specify regexps that matches Objective-C category names or Objective-C category target class names or both of them concatenated and separated by a @. For categories targeting classes in the current framework the default is to add the category methods to that class. For other categories the default is to create a new class with the name <category>Extensions that extends NSExtensions and that has static methods for each category method.

functions

The keys in this hash specify regexps that matches C function names. Functions not matching any key in this hash will be ignored. Java doesn't have global functions so each function will be convered into a method on a particular class. If no class is explicitly specified it will be assigned to a class named the same as the framework code is being generated for. If not generating code for a framework the default is to add functions to a class named Functions.

The generated method for a function will by default be an instance method if the first parameter of the C function is a pointer to the class or struct corresponding to the Java class it will be added to. Otherwise is will be static.

Note that Bro does not currently support variable parameter functions so such methods will be ignored.

values

The keys in this hash specify regexps that matches C global value names. Values not matching any key in this hash will be ignored. Java doesn't have global values so each value will be converted into a getter method and a setter method (if not readonly) on a particular class. If no class is explicitly specified they will be assigned to a class named the same as the framework code is being generated for. If not generating code for a framework the default is to add value methods to a class named Functions.

constants

The keys in this hash specify regexps that matches C constants (macros). Constants not matching any key in this hash will be ignored. Java doesn't have global constants so each constant will be added as a static final field on a particular class. If no class is explicitly specified it will be assigned to a class named the same as the framework code is being generated for. If not generating code for a framework the default is to add constants to a class named Functions.

Enums in the framework or library being generated which don't have a match in the enums config will be convered into constants and matched against the keys in this hash.

properties

The keys in a properties hash are regexp patterns matching Objective-C property names. The script will generate getter and setter (if not readonly) methods for the property. The values of the hash are hashes with the following keys:

methods

The keys in a methods hash are regexp patterns matching Objective-C method (selector) names. The Obj-C selector will be prefixed with + for static methods and - for instance methods before finding a match.

The script will be default use the selector with all : replaced by $ as Java method name. For setter like methods the ending : will be dropped by default.

Note that Bro does not currently support variable parameter methods so such methods will be ignored.

The values of the hash are hashes with the following keys: