tonyaim83 -2 Light Poster

Hi
I m new to ruby so kindly forgive for small mistakes. I m trying to invoke a c function in ruby which uses a structure * as a parameter but i m able to run in one example and it is not running in the other case.

Program which is running fine

File Name:- test_struct.h

#include <iostream>
struct Mystruct
{
     int a;
     float b;
};

File Name:- test_struct.cpp

#include"test_struct.h"

void My_initialize(Mystruct *s1)
{
    s1->a=10;
    s1->b=12.3;
}

void Print(Mystruct *s1)
{
     std::cout<<"\n a "<<s1->a;
     std::cout<<"\n b"<<s1->b;
}

File Name :- test_struct.i

%module test_struct
%{
          #include "test_struct.h"
          extern void My_initialize(Mystruct *s1);
          extern void Print(Mystruct *s1);

%}

%include "test_struct.h"
  extern  void My_initialize(Mystruct *s1);
  extern  void Print(Mystruct *s1);

File Name :- test_struct.rb

require "test_struct.so"
a = Test_struct::Mystruct.new
Test_struct.My_initialize(a)
Test_struct.Print(a)

Now when i change the name from Test_struct to test_struct in the .rb file it gives me an error
test_struct.rb:4: undefined local variable or method `test_struct' for main:Object (NameError)


Now when i use the exact thing as :-

File Name :- New_struct.h

#include<iostream>

struct TestStruct
{
 std::string str;
 std::string abc;
};

File Name :- New_struct.cpp

#include "New_struct.h"

void AssignS(TestStruct *t1)
{
 t1->str="Apple";
 t1->abc="Ball";
}
void Print(TestStruct *t2)
{
 std::cout<<t2->str;
 std::cout<<"\n" <<t2->abc;
}

File Name :- New_struct.i

%module New_struct
%{
          #include "New_struct.h"
          extern void AssignS(TestStruct *s1);
          extern void Print(TestStruct *s1);

%}

File Name :- New_struct.rb

require "New_struct.so"

#puts((Test_struct.methods - Object.new.methods).sort)
a = New_struct::Teststruct.new
New_struct.AssignS(a)
New_struct.Print(a)

When i try to run this it gives me following error
New_struct.rb:4: uninitialized constant New_struct::Teststruct (NameError)