#include "lua_corepp.h"


static int luacv_cvMat(lua_State *L)
{
 size_t top=lua_gettop(L);
 vector<string> names2, &names=luacv_getnames(L);
 switch(top)
  {
    case 0:
            pushMat(L,new cv::Mat()); 
            return 1;
    case 1:
            names2.push_back(string(MAT_NAME));
            if(luacv_compare(names,names2))
            {
              pushMat(L,new cv::Mat(*checkMat(L,1))); 
              return 1;
            }
            names2.clear();
            names2.push_back(string(CVMAT_NAME));
            if(luacv_compare(names,names2))
            {
              pushMat(L,new cv::Mat(checkCvMat(L,1)));
              return 1;
            }
            names2.clear();
            names2.push_back(string(IPLIMAGE_NAME));
            if(luacv_compare(names,names2))
            {
              pushMat(L,new cv::Mat(checkIplImage(L,1)));  
              return 1;
            }
            names2.clear();
            names2.push_back(string(CVMATND_NAME));
            if(luacv_compare(names,names2))
            {
              pushMat(L,new cv::Mat(checkCvMatND(L,1)));  
              return 1;
            }

            break;
 /*   case 2:
            names2.push_back(string("Size"));
            names2.push_back(string("number"));
            if(luacv_compare(names,names2))
            {
              break;
            }
            names2.clear();
            names2.push_back(string(MAT_NAME));
            names2.push_back(string("Rect"));
            if(luacv_compare(names,names2))
            {
              break;
            }
            names2.clear();
            names2.push_back(string(CVMAT_NAME));
            names2.push_back(string("number"));
            if(luacv_compare(names,names2))
            {
              break;
            }
            names2.clear();
            names2.push_back(string(CVMATND_NAME));
            names2.push_back(string("number"));
            if(luacv_compare(names,names2))
            {
              break;
            }
            names2.clear();
            names2.push_back(string(IPLIMAGE_NAME));
            names2.push_back(string("number"));
            if(luacv_compare(names,names2))
            {
              break;
            }




            break;
    case 3:

            break;
            */
    default:
            luaL_error(L,"argument error");
  }

  return 1;
}

const luacv_var corepp_object[]=
{
//  {MAT_NAME,sizeof(cv::Mat)},
  {NULL,0}
};

const luaL_Reg corepp[]=
{
  funcReg(Mat),
  {NULL,NULL}
};

const luacv_var corepp_var[]=
{
  {NULL,0}
};


extern "C" {
#if defined(WIN32) || defined(WIN64)
__declspec(dllexport) 
#endif
int luaopen_luacv_corepp(lua_State *L)
{
  coreppReg()
  objectReg(COREPP_NAME,luacv_m);

  luaL_requiref(L,CORE_NAME,luaopen_luacv_core,1);
  lua_pop(L,1);

  luaL_newlib(L,corepp);

  luacv_objTableReg(L,corepp_object);
  luacv_constReg(L,corepp_var);

  luaL_getmetatable(L,COREPP_NAME);
  lua_setmetatable(L,-2);
  return 1;
}
}
