Classes and native objects. More...
Classes | |
| struct | flusspferd::class_info |
| Information about classes exposed to javascript. More... | |
| class | flusspferd::native_object_base |
| Native object base. More... | |
Defines | |
| #define | FLUSSPFERD_CLASS_DESCRIPTION(cpp_name, named_parameters) ... |
Generate a loadable class named cpp_name. | |
Functions | |
| template<typename T > | |
| object | flusspferd::load_class (object container=global()) |
| Expose a class to Javascript. | |
| template<typename T > | |
| boost::enable_if< typename boost::is_base_of < native_function_base, T > ::type, T & >::type | flusspferd::get_native (object const &o) |
Gets o as native function of class T. | |
| template<typename T > | |
| boost::enable_if< typename boost::is_base_of < native_function_base, T > ::type, bool >::type | flusspferd::is_native (object const &o) |
Checks if o is a native function of class T. | |
Classes and native objects.
| #define FLUSSPFERD_CLASS_DESCRIPTION | ( | cpp_name, | |||
| named_parameters | ) | ... |
Generate a loadable class named cpp_name.
Also generates a template class cpp_name_base<T>. This class contains a typedef base_type to itself, and it is the direct base class of cpp_name. This implies that inside cpp_name, the identifier base_type can be used to reference the direct base class, especially in constructors.
The class base_type has forwarding constructors to its base class (by default flusspferd::native_object_base), taking each parameter as a constant reference to its type. These forwarding constructors can be used to initialize the real (indirect) base class.
Most importantly, base_type contains a class class_info, with all elements set according to the named parameters.
FLUSSPFERD_CLASS_DESCRIPTION( cpp_name, (parameter_name_1, parameter_value_1) (parameter_name_2, parameter_value_2) ... ) { CONTENTS };
| cpp_name | The name of the generated class. | |
| named_parameters | A sequence of named parameters in the form (parameter1_name, parameter2_value) (parameter2_name, parameter2_value) ... |
instanceof works). 0. true. (method_name, type, parameter)..., where method_name is a string. (~, none, ~) (method_name, type, parameter)..., where method_name is a string. (~, none, ~) (property_name, type, parameter)..., where property_name is a string. (~, none, ~) (property_name, type, parameter)..., where property_name is a string. (~, none, ~) true. cpp_name::augment_constructor(ctor) will be called with the constructor object as parameter when the Javascript constructor is being generated by flusspferd::load_class (or more specifically, base_type::class_info::augment_constructor). cpp_name::augment_prototype(ctor) will be called with the prototype object as parameter when the Javascript constructor is being generated by flusspferd::load_class (or more specifically, base_type::class_info::create_prototype). methods and constructor_methods take sequences with elements of the form (method_name, type, parameter), where type is one of the identifiers mentioned below. (?, none, ?) (~, none, ~) because empty sequences are not valid. (name, bind, method) name to non-static method cpp_name::method. (name, bind_static, method) name to the static method cpp_name::method. (name, alias, alias_name) alias_name into a property with name name. The method alias_name must be already defined above this method. (name, function, (signature, expression)) Class instead of the class name in the expression. (name, method, (signature, expression)) Class instead of the class name in the expression! properties and constructor_properties take sequences with elements of the form (property_name, type, parameter), where type is one of the identifiers mentioned below. (?, none, ?) (~, none, ~) because empty sequences are not valid. (name, getter_setter, (getter, setter)) cpp_name::getter and cpp_name::setter. (name, getter, getter) cpp_name::getter. (name, variable, initial_value) initial_value. (name, constant, value) value. (name, getter_expression, (signature, expression)) Class instead of the class name in the expression! (name, getter_setter_expression, (getter_signature, getter_expression, setter_signature, setter_expression)) Class instead of the class name in the expression! FLUSSPFERD_CLASS_DESCRIPTION( my_class, (full_name, "MyModule.MyClass") (constructor_name, "MyClass") (methods, ("myMethod", bind, my_method) ("anotherName", alias, "myMethod")) (constructor_methods, ("constructorMethod", bind_static, constructor_method)) (constructor_properties, ("VERSION", constant, "1.0"))) { double my_method(double parameter) { return parameter * 2; } static double constructor_method(double parameter1, int parameter2) { return parameter1 + parameter1; } }; void some_function() { flusspferd::load_class<my_class>(); }
| boost::enable_if< typename boost::is_base_of< native_object_base, T >::type, T & >::type flusspferd::get_native | ( | object const & | o | ) | [inline] |
Gets o as native function of class T.
Gets o as native object of class T.
If o is not a function, not native or not of class T then an exception will be thrown.
| o | object to check |
If o is not an object, not native or not of class T then an exception will be thrown.
| o | object to check |
| boost::enable_if< typename boost::is_base_of< native_object_base, T >::type, bool >::type flusspferd::is_native | ( | object const & | o | ) | [inline] |
Checks if o is a native function of class T.
Checks if o is a native object of class T.
flusspferd::object o = v.get_object(); if (flusspferd::is_native<my_fun>(o) { my_fun &b = flusspferd::get_native<my_fun>(o); }
| o | object to check |
flusspferd::object o = v.get_object(); if (flusspferd::is_native<flusspferd::binary>(o) { flusspferd::binary &b = flusspferd::get_native<flusspferd::binary>(o); }
| o | object to check |
| object flusspferd::load_class | ( | object | container = global() |
) | [inline] |
Expose a class to Javascript.
If the class is not constructible, trying to create an instance of the class will throw an error. A dummy "constructor" will be created though.
The class name is pulled from the class's class_info struct, as well as other information.
| container | Object in which to define the constructor. |
Contact us at team -AT- flusspferd -DOT- org or as described on our homepage.
Generated on Fri Sep 3 19:05:01 2010 for Flusspferd by
1.6.1