Bindings¶
Language bindings from a non-C++ language (Python, Java, ...) are translation layers towards libqi (C++). No intelligence should be implemented in these translation layers, but values should be translated to C++ types in the appropriate manner.
See Type equivalences between languages.
The null value¶
Many languages feature a null value, representing the absence of a valid value. In some language, such as python, it is called a none value.
Such a null / none value must be translated to the Void qi type.
Example for Java¶
This JNI code creates an AnyReference for the given Java object:
qi::AnyReference AnyReference_from_jobject(jobject obj)
{
// obj is a Java object.
if (env->IsSameObject(obj, NULL)) {
// obj is null
return qi::AnyReference(qi::typeOf<void>());
} else {
// For non null just wrap the value
return qi::AnyReference::from(obj);
}
}
Example for Python¶
qi::AnyReference AnyReference_from_PyObject(PyObject* obj)
{
if (obj == Py_None)
{
// obj is none
return qi::AnyReference(qi::typeOf<void>());
}
// else if...
}