All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reference.language.bindings_categories.html Maven / Gradle / Ivy




    
    Errors
    
    

    
    

    
    

    
    
    
    

    


Binding categories

Prompto can expose native objects, and interact with them, as if they were Prompto objects. This is acheved using Prompto native categories. Native categories have a lot in common with regular Prompto categories, with the following exceptions:

  • They cannot inherit from other categories
  • They cannot be enumerated
  • They only support native methods
  • They may have no attribute

Binding categories

The first step in binding categories is to bind the Prompto category itself to an host language equivalent. Binding categories is done as follows:

Notice the native keyword in the category definition. This denotes a binding category.

The category body must comprise exactly 1 category binding statement, which must itself comprise exactly 1 binding statement per supported host language.

Binding a category with a Java class

Binding a category with a Java class is done by using the Java: keyword, followed by a Java full class name.

The class must have a public parameter-less constructor.

Java: java.io.PrintStream

Binding a category with a C# class

Binding a category with a C# class is done by using the C#: keyword, followed by a C# full class name.

The class must have a public parameter-less constructor.

C#: System.IO.TextWriter

Binding a category with a Python 2 class

Binding a category with a Python 2 class is done by using the Python2: keyword, followed by a Python 2 class name.

If the Python 2 statement refers to a class which does not belong to the global namespace, the import module must be provided.

Python2: StringIO from module: StringIO

Binding a category with a Python 3 class

Binding a category with a Python 3 class is done by using the Python2: keyword, followed by a Python 3 class name.

If the Python 3 statement refers to a class which does not belong to the global namespace, the import module must be provided.

Python3: StringIO from module: io

Binding a category with a JavaScript function

Binding a category with a JavaScript function is done by using the JavaScript: keyword, followed by a JavaScript function name.

The JavaScript function must have a prototype, and the constructor must return this.

If the JavaScript is a method or variable which does not belong to the global namespace, the import module must be provided.

JavaScript: writer from module: prompto/io/io.js

Binding attributes

Prompto automatically binds category attributes, if any, to their corresponding host language equivalent. This may require providing a "proxy" class in the host language which maps Prompto attribute names to actual names. Alternately, attribute name bridging can be achieved using native getters and setters.

The below is an example of using a getter to bind an attribute:

Binding methods

Prompto native categories can have methods, like regular Prompto categories, these methods simply need to be native.

Prompto native category methods share a lot with Prompto native global methods. The only difference is they can make use of this or self, which both represent the native instance in all host languages.

Here is an example:





© 2015 - 2025 Weber Informatics LLC | Privacy Policy