Skip to content

How to write a plugin?

Gabor de Mooij edited this page Feb 7, 2016 · 1 revision

Take a look at the example plugin: Percolator.

To create a plugin, simply create a .c file, add a constructor definition:

void begin (void) __attribute__((constructor));

Now you can init your plugin:

void begin(){
   ...do stuff...
}

In your init function (begin) you add objects to the world like this:

 ctr_internal_object_add_property(CtrStdWorld, 
      ctr_build_string("Percolator", 10),
      percolatorObject,
      CTR_CATEGORY_PUBLIC_PROPERTY
 );

CtrStdWorld contains the world, here we add a new object called Percolator as a public property.

Now you can add methods to your new object:

ctr_object* ctr_percolator_add_coffee_water(
     ctr_object* myself, 
     ctr_argument* argumentList) {
          ...method does stuff...
}

and add the method to the object:

ctr_internal_create_func(
      percolatorObject,
      ctr_build_string("coffee:water:", 13),
      &ctr_percolator_add_coffee_water);

To read a property of an object in C:

  ctr_object* coffee = ctr_internal_object_find_property(
        myself,                        /* owner object */
        ctr_build_string("coffee", 6), /* key object */
        CTR_CATEGORY_PRIVATE_PROPERTY
  );
Clone this wiki locally