•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Ruby section within the Web Development category of DaniWeb, a massive community of 375,207 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,318 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Views: 729 | Replies: 0
![]() |
•
•
Join Date: Aug 2007
Posts: 44
Reputation:
Rep Power: 0
Solved Threads: 0
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
File Name:- test_struct.cpp
File Name :- test_struct.i
File Name :- test_struct.rb
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
File Name :- New_struct.cpp
File Name :- New_struct.i
File Name :- New_struct.rb
When i try to run this it gives me following error
New_struct.rb:4: uninitialized constant New_struct::Teststruct (NameError)
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
c++ Syntax (Toggle Plain Text)
#include <iostream> struct Mystruct { int a; float b; };
File Name:- test_struct.cpp
c++ Syntax (Toggle Plain Text)
#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; }
ruby Syntax (Toggle Plain Text)
%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);
ruby Syntax (Toggle Plain Text)
require "test_struct.so" a = Test_struct::Mystruct.new Test_struct.My_initialize(a) Test_struct.Print(a)
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
c++ Syntax (Toggle Plain Text)
#include<iostream> struct TestStruct { std::string str; std::string abc; };
c++ Syntax (Toggle Plain Text)
#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; }
ruby Syntax (Toggle Plain Text)
%module New_struct %{ #include "New_struct.h" extern void AssignS(TestStruct *s1); extern void Print(TestStruct *s1); %}
File Name :- New_struct.rb
ruby Syntax (Toggle Plain Text)
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)
New_struct.rb:4: uninitialized constant New_struct::Teststruct (NameError)
Last edited by peter_budo : May 16th, 2008 at 5:37 pm. Reason: Swaping forward slash to back slash in first code tag
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Ruby Marketplace
Other Threads in the Ruby Forum
- Previous Thread: New to Ruby
- Next Thread: f.check_box help


Linear Mode