next up previous contents
Next: tFunc Up: The C API Previous: Pike_fp-current_storage   Contents

ADD_FUNCTION()

/*Macro:*/
   ADD_FUNCTION(NAME, FUNC, TYPE, FLAGS)
ADD_FUNCTION() is a macro to define a Pike level method and map it to a C level function in the module. It takes four arguments. The first argument is the Pike level name of the function (or method as it is called on the Pike level). This is the name a Pike programmer will call the method by. Note that this argument is a string (array of characters). The second argument is the name of the corresponding C level function. That means that when the Pike method with the name equal to the first argument is invoked, Pike will look for the C function with a name equal to the second argument and run that function. The third argument specifies what type of method it is and what arguments the method takes. As it is seen in the example the macro tFunc() is used in order to specify the third argument. The fourth argument is a flag that specifies the modifier of the method.

The following example of usage adds a method that has one string as argument and an integer as second optional argument. The return value of the method is of type array.

/*Example of usage:*/
   ADD_FUNCTION("my_method", my_method_C_impl,
                tFunc(tString tOr(tInt,tVoid),tArray), 0);
A Pike declaration of the method would look like this:
   array my_method(string str, int|void number)


next up previous contents
Next: tFunc Up: The C API Previous: Pike_fp-current_storage   Contents
2003-03-04