Functions

Now that we have access to the internal data of our class, we need to define some operations. We will extend our point class:

    class point : public object {
    public:
	//construction
	point(double x,double y,double z);

	//operations
	bool inPlane(const point& p1,const point& p2,const point& p3);
	point project(const line& l1); //project point onto line

	//access
	double get_x() const;
	...
	void set_z(double z);
    private:
	double x_,y_,z_;
    };

As with properties, there are several ways to expose functions to CliPP:

There  are two ways to expose dynamic functions of a class:

There are also two ways to expose static functions of a class:

Here are some examples of the different forms for access:

    //dynamic data access:
    bool point::inPlane(const point& p1,const point& p2,const point& p3); 	//member-functions
    bool is_origo(const point& p_this);						//free functions as member
    //static data access:
    double intersect_lines(const line& l1,const line& l2);			//free function
    point project(const line& l1);							//member-functions as static

And this is how to expose the above to CliPP:

    //dynamic data access:
    cls.function("inPlane",inPlane);							//member-functions
    cls.function("is_origo",is_origo);							//free functions as member

    //static data access:
    cls.static_function("intersect_lines",intersect_lines);			//free function
    cls.static_function("project",project);						//member-functions as static

//Optional syntax:

    //dynamic data access:
    cls["inPlane"] = function(inPlane);						//member-functions
    cls["is_origo"]= function(is_origo);						//free functions as member

    //static data access:
    cls["intersect_lines"]=static_function(intersect_lines);			//free function
    cls["project"]		=static_function(project);				//member-functions as static

Alternatively:

static functions can also be made available globally:

    context* c=parser.get_context();
    //static data access:
    function(c,"intersect_lines",intersect_lines);			//free function
    function(c,"project",project);					//member-functions as static

Let's examine how this looks in context of Javascript:

    var point1=new point(4,5,6);

    //point's functions
    //member-functions
    point1.inPlane(point(0,0,0),point(0,10,0),point(10,10,0));

    //free functions as member
    point1.is_origo();

    //free function
    point1.intersect_lines(line1,line2);
    point.intersect_lines(line1,line2);

    //member-functions as static
    point1.project(point1,line1);
    point.project(point1,line1);

    //global functions
    //free function
    intersect_lines(line1,line2);

    //member-functions as static
    project(point1,line1);
Limitations to number of arguments

By default, Clipp is restricted to handle free functions with 10 arguments and member functions with 9 arguments. If you need more than 10 arguments for a function or a constructor, you can set a new value for the BOOST_CLIPP_MAX_ARITY macro. This should be done in the cpp file where you expose the function with more than 10 arguments, and it should be set before the first include statement.
BOOST_CLIPP_MAX_ARITY can not be greater that 47 because of limitations in boost::mpl.