From: Avneet K. <kau...@gm...> - 2014-01-25 19:05:07
|
Hello, I am new to SWIG. I want to create PHP wrappers from C++ class Book. Please guide me to solve this error. I have explained every step that I did. It's urgent to deliver this my college project. Please help to get me out. :) STEP 1: Source file We have source .cc file in which we have defined the following function in Book class. //book.cc file bool Book::page(string fname, Pageid &pid) { } STEP 2: SWIG Interface To create a PHP wrapper, we defined following swig interface: %{ #include "Book.cc" %} %module Book %include "typemaps.i" %include "std_string.i" class Pageid{ }; class Book{ public: bool page(string filename, Pageid &pid); }; STEP 3: SWIG Generated .cpp and .php files //Book_wrap.cpp ZEND_NAMED_FUNCTION(_wrap_Book_page) { Book *arg1 = (Book *) 0 ; string arg2 ; Pageid *arg3 = 0 ; string *tmp2 ; zval **args[3]; bool result; SWIG_ResetError(); if(ZEND_NUM_ARGS() != 3 || zend_get_parameters_array_ex(3, args) != SUCCESS) { WRONG_PARAM_COUNT; } { if(SWIG_ConvertPtr(*args[0], (void **) &arg1, SWIGTYPE_p_Book, 0) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument 1 of Book_page. Expected SWIGTYPE_p_Book"); } } if(!arg1) SWIG_PHP_Error(E_ERROR, "this pointer is NULL"); { if(SWIG_ConvertPtr(*args[1], (void **) &tmp2, SWIGTYPE_p_string, 0) < 0 || tmp2 == NULL) { SWIG_PHP_Error(E_ERROR, "Type error in argument 2 of Book_page. Expected SWIGTYPE_p_string"); } arg2 = *tmp2; } { if(SWIG_ConvertPtr(*args[2], (void **) &arg3, SWIGTYPE_p_CCard, 0) < 0 || arg3 == NULL) { SWIG_PHP_Error(E_ERROR, "Type error in argument 3 of Book_page. Expected SWIGTYPE_p_Pageid"); } } result = (bool)(arg1)->page(arg2,*arg3); { ZVAL_BOOL(return_value,(result)?1:0); } return; fail: zend_error(SWIG_ErrorCode(),"%s",SWIG_ErrorMsg()); } //// Book.php class Book { public $_cPtr=null; protected $_pData=array(); function __set($var,$value) {} function __isset($var) { } function __get($var) { } function page($filename,$pid) { return Book_page($this->_cPtr,$filename,$pid); } function __construct($res=null) { } } STEP 4: Testing ///// Test file: test.php <?php include_once "Book.php"; $pid = new Pageid(); $filename = "52c576d32647b.jpg"; $bk = new Book(); $cr->processCard($filename, $pid); ?> ERROR: // while running, error message: PHP Fatal error: Type error in argument 2 of Book_page. Expected SWIGTYPE_p_string in /home/avneet/Book.php on line 120 There is something wrong with SWIG Interface file. Please let me know where I am wrong. Eagerly waiting for reply ! -- Er. Avneet Kaur Blog: www.avneetkhasla.wordpress.com "Coming together is a beginning; keeping together is progress; working together is success." |