Forum: Ruby problem in Extending ruby

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2bfb72f11d1b323f14f026aaa660a8fb?d=identicon&s=25 ravinder (Guest)
on 2007-03-21 17:47
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
C76a52a7216844fe0e462e3d39ac97e4?d=identicon&s=25 Alexander Fleck (Guest)
on 2007-03-22 08:41
(Received via mailing list)
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.

D7f3b9d3cfb10e0f9e0f2c875d164e7d?d=identicon&s=25 barabba (Guest)
on 2007-03-23 23:11
(Received via mailing list)
On Mar 21, 5:47 pm, ravinder <> 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.
This topic is locked and can not be replied to.