logo       

Returning values from pointer args with SWIG + TCL: msg#00141

programming.swig

Subject: Returning values from pointer args with SWIG + TCL

Eyal Raab writes:
> Hi,
>
> I'd like to thank everyone for helping me with my previous problem -
> Thanks to you, I managed to get SWIG 1.1-883 to work with TCL 7.3 on
> VxWorks.
>
> The problem I'm having currently is the following:
>
> Let's say I have the following C function:
> * Basicallly, it's a simple C function that retrieves the ID of the
> table given by TableName.
> * The result is stored in the TableID pointer.
>
> CS_RETCODE DB_GetTableID (char *TableName, // Table name
> CS_UINT32 *TableID) // Table identifier
> {
> CS_UINT32 i;
>
> for ( i=0; i<s_dbSize; i++ )
> {
> //printf( "%d) %s ?= %s \n", i, s_db[i].Name, TableName);
> if ( strcmp(TableName,s_db[i].Name) == 0 )
> {
> *TableID = i;
> return RC_OK;
> }
> }
> return RC_NO_SUCH;
> }
>
> The generater swig function is the following:
>
> static int _wrap_DB_GetTableID(ClientData clientData, Tcl_Interp *interp,
> int argc, char *argv[])
> {
>
> CS_RETCODE _result;
> char * _arg0;
> CS_UINT32 * _arg1;
>
> clientData = clientData; argv = argv;
> if ( (argc < 3) || (argc > 3) )
> {
> Tcl_SetResult(interp, "Wrong # args. DB_GetTableID TableName
> TableID ",TCL_STATIC);
> return TCL_ERROR;
> }
> _arg0 = argv[1];
> if ( SWIG_GetPtr(argv[2],(void **) &_arg1,"_CS_UINT32_p") )
> {
> Tcl_SetResult(interp, "Type error in argument 2 of
> DB_GetTableID. Expected _CS_UINT32_p, received ", TCL_STATIC);
> Tcl_AppendResult(interp, argv[2], (char *) NULL);
> return TCL_ERROR;
> }
> _result = (CS_RETCODE )DB_GetTableID(_arg0,_arg1);
> sprintf(interp->result,"%lu", (unsigned long) _result);
> return TCL_OK;
> }
>
> Here is my problem:
> * How to I return to TCL the value stored in _arg1?
> * To put it another way, can I configure SWIG to insert these values
> into the TCL result automatically through some configuration options?
>
> Could anyone supply some pointers?
>

The "typemaps.i" library file is typically used to do this sort of
thing. Look at that file for some clues.

Cheers,
Dave
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise