#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <mex.h>

#include <mexhelper.h>
#include "add/add.ri"

extern "C"
{
void mexFunction (int nresults, mxArray **arrresults, int nargs,
		const mxArray **arrargs)
{
	int arg0 = 0;
	if (nargs > 0)
		mexConvert(arrargs[0], arg0);
	int arg1 = 0;
	if (nargs > 1)
		mexConvert(arrargs[1], arg1);

	try
    {
		initEnv();
		int res = AddRi::add(arg0, arg1);
		
		if (nresults > 0)
		{
			mexConvert(res, arrresults[0]);
		}
	}
	catch(ctl::exception &e)
	{ 
		std::cerr << e << "\n"; 
	}	
}
}
