problem in Extending ruby

R

ravinder

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
 
B

barabba

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top