next up previous contents
Next: Define the Pike Level Up: Writing a C Module Previous: Init and Exit Routines   Contents

An Example - The Rev Module

This is a very simple C module. This text contains extracts of its code. The whole source code file can be found at the end of this appendix. A CMOD implementation of this module does not exist but some extracts of the code has been translated to CMOD.

The module has one class called ReversedString. This class has two methods: the mandatory create() method, and a method write(). The ReversedString class takes the 49 first characters of a string, reverses the string, and stores it as an object variable. A call to the method write() writes the content of the reversed string nr_of_times times to the screen. As we can see the module is totally useless, it is just an example to illustrate how a module is written.



2003-03-04