Next: , Previous: Kite Language Specification, Up: Top


4 Extending Kite

There are two ways to extend Kite: write your own classes/packages and writing your own compiled extensions.

4.1 Kite Packages

To write a package, it is a simple matter of saving your classes and other code in a file with the .kt extension. For example, here is a simple package:

     #!/usr/bin/kite
     
     class Greeting [
         property text,
         method sayGreeting() [
             text|print;
         ]
     ];
     
     class Hello from Greeting [
         construct [
             this.text = "Hello!";
         ]
     ];
     
     class Hola from Greeting [
         construct [
             this.text = "¡Hola!";
         ]
     ];

We shall call this Greetings.kt. Now, where should this be placed? We know that greetings fall under common sayings, so let's place this in the CommonSayings folder. Now, the package can be referenced by using import CommonSayings.Greetings in any Kite application. Let's try it:

     #!/usr/bin/kite
     
     import "CommonSayings.Greetings";
     greetings = CommonSayings.Greetings;
     
     english = make greetings.Hello;
     spanish = make greetings.Hola;
     
     english|sayGreeting;
     spanish|sayGreeting;

Assuming that your folder structure looks like this:

     ./CommonSayings/
     ./CommonSayings/Greetings.kt
     ./test.kt

Running kite test.kt will produce:

     Hello!
     ¡Hola!

Easy enough, but what if your package isn't in the current Kite search path? You'll have to use something like this to fix that:

     #!/usr/bin/kite
     
     import "System.vm.loader";
     System.vm.loader.searchPath = System.vm.loader.searchPath + ":/path/to/package";
     greetings = System.vm.loader|loadClass("CommonSayings.Greetings");
     
     english = make greetings.Hello;
     spanish = make greetings.Hola;
     
     english|sayGreeting;
     spanish|sayGreeting;

Now, it'll work as intended.

Caution: import will only load a class once during runtime. If you need to reload the package for any reason, you'll currently need to restart Kite. (This is on the TODO for future releases.)

4.2 Compiled Extensions

Compiled extensions are the second route to extending Kite. Right now, this isn't well documented, but you can see how to write one by looking at modules/System/string.c in the Kite distribution. The loading process is similar to packages written in Kite, but the difference is the extension is a shared library object, usually compiled by gcc using something like the following:

     gcc -shared -o library.so file1.c file2.c ...

If you have Doxygen, you can generate documentation for all of the Kite internals by running doxygen Doxyfile from the top of the distribution. It should place HTML and LaTeX files in docs/html and docs/latex, respectively.