Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > swig problem

Reply
Thread Tools

swig problem

 
 
dominic sisneros
Guest
Posts: n/a
 
      04-02-2004
I am trying to wrap a function that either takes a char * or NULL
How would I wrap this in swig?

The c version accepts a conts char * or NULL

librdf_node* librdf_new_node_from_blank_identifier(librdf_world *world,
const char * identifier);

I do a typemap as follows

I tried this but am still getting a TypeError converting Nil to String

%typemap(ruby,in) const char *identifier {
if $input == Qnil{
$1 == NULL;
else
$1 = STR2CSTR($input);
}
}



 
Reply With Quote
 
 
 
 
Tobias Peters
Guest
Posts: n/a
 
      04-02-2004
dominic sisneros wrote:
> I do a typemap as follows
>
> I tried this but am still getting a TypeError converting Nil to String
>
> %typemap(ruby,in) const char *identifier {
> if $input == Qnil{
> $1 == NULL;
> else
> $1 = STR2CSTR($input);
> }
> }


Rerun swig and recompile your extension before trying again

I can see you didn't because there are 2 syntax errors (and 1 semantic
error) in your typemap. Your compiler would have caught the 2 syntax
ones. Or maybe you just didn't notice the error messages.

- C requires that you parenthesize the test expression after the "if"
- Your "else" has no previous "if" (removing the inner braces will help)
- "$1 == NULL" doesn't do anything.

Apart from these errors, your typemap is correct and your code will work
once you correct them.

Tobias

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sip problem (was: swig problem) Uwe Mayer Python 0 02-16-2004 05:05 PM
Newbie has problem changing C char strings with Python/SWIG Rick Olson Python 0 01-09-2004 03:05 AM
Swig - problem with visual c++ extension exercise S Green Python 1 11-26-2003 05:22 PM
Problem using swig Alfonso Cepeda Caballos,,, Python 0 11-04-2003 03:47 PM
SWIG, MinGW, and Python 2.3 problem Phil Schmidt Python 0 09-10-2003 05:52 PM



Advertisments