Problem in Extending ruby


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:
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 =
convert = Converter.a_conv_a2b_withlen(“a sample test”, 13, “”, 100,

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.

Ravinder Singh


look at

There’ re some issues to think about when you use structs and variables
Ruby and C.

I don’ t have the time to get deeper at the moment. Perhaps later.



On Mar 21, 5:47 pm, ravinder removed_email_address@domain.invalid wrote:

} Version;

convert = Converter.a_conv_a2b_withlen(“a sample test”, 13, “”, 100,

Posted via

May be you have to use something like I
suggest you to look inside the generated file from swig to know how
the structure GenParams is converted.