Pink 0.9
Namespaces

ui_make_malloc.hpp File Reference

This is a helper function for exporting Pink C functions in Python. Note that this template file is rarely used directly and is called by the UI_WRAP_FUNCTION macro. More...

Namespaces

namespace  pink

Detailed Description

This is a helper function for exporting Pink C functions in Python. Note that this template file is rarely used directly and is called by the UI_WRAP_FUNCTION macro.

Note

For debugging macro definitions you can use the

  g++ -E -P file.cpp -o file_pp.cpp
  

commands, which outputs the source code after preprocessing. Also

  astyle -A3 -z2 -k1 -s2 -j file_pp.cpp 
  

Indents the preprocessed code and inserts lot's of newlines, which improoves very much the readability of the code.

Exporting functions from C

For exporting functions from Pink you should make them follow the Conventions for developing Pink operators.

You may use printf and you may call exit(1) if there's an error. type_k can be any type that python recognizes (int, float, ...) and xvimage* The return value is 1 on success and 0 otherwise. To export this function you should include a function call in pypink.cpp of the form

make_malloc is a template. In the first parameter you specify the image type. Second, you specify the types of the parameters and last you put the pointer to your Pink function.

Example:

Advanced

This file contains C++ macro language and template metaprogramming, which is difficult to understand. The file is first treated with the preprocessor. The generated code looks like this:

The macro generates the make_malloc template for each number of parameters. The template takes the specified parameters and wraps the function in Python. The most important part of the macro is the conversion of the 'xvimage*' pointer into the appropriate image class (like 'char_image').