From: barabba Date: 2007-03-24T07:10:12+09:00 Subject: Re: problem in Extending ruby On Mar 21, 5:47 pm, ravinder wrote: > I want to call C code from my ruby class. I am using SWIG for doing > this. I am able to compile the code and also able to invoke a C function > from ruby, but am unable to access a variable. > I have declared the variable as follows in "test.h" file: > > typedef struct GenParams_s { > Version a_version; /**< Version */ > BOOL keep_ignorable; /**< Keep Ignorable Whitespaces (Default: > FALSE) */ > BOOL use_strtbl; /**< Generate String Table (Default: TRUE) > */ > > } GenParams; > > typedef enum Version_e { > VERSION_UNKNOWN = -1, /**< Unknown Version */ > VERSION_10 = 0x00, /**< 1.0 Token */ > VERSION_11 = 0x01, /**< 1.1 Token */ > VERSION_12 = 0x02, /**< 1.2 Token */ > VERSION_13 = 0x03 /**< 1.3 Token */ > > } Version; > > #define BOOL unsigned char > > Now I have another class "Convert.c", in which I have declared the > functions which I want to call from ruby. One of the method has > following signature: > > A_DECLARE(Error) a_conv_a2b_withlen(UTINY *a, ULONG a_len, UTINY **b, > ULONG *b_len, > GenParams *params) > > UTINY and ULONG are declared as unsigned char and unsigned long > respectively. I am importing "test.h" file in "Convert.c" file. > > Next I compile "Convert.c" file using nmake etc...(as required by SWIG). > Now I want to access the method defined in Convert.c file, which I am > doing as follows: > > require 'converter' > > params = GenParams.new > convert = Converter.a_conv_a2b_withlen("a sample test", 13, "", 100, > params) > > and getting following error: > "uninitialized constant GenParams (NameError)" > > I'd appreciate if anyone can help me in this case or suggest me a > pointer as to where to look. > > Thanks, > Ravinder Singh > > -- > Posted viahttp://www.ruby-forum.com/. May be you have to use something like Converter::GenParams.new. I suggest you to look inside the generated file from swig to know how the structure GenParams is converted.