----- Original Message ----- From: "Tallapragada, Sridevi" <[EMAIL PROTECTED]> To: <inline@perl.org> Sent: Thursday, October 12, 2006 11:44 PM Subject: How to use Inline::Structs
> The following perl program doesn't work. I have copied this to temp.pl > and executed "perl temp.pl" > > use Inline C => Config => Structs => ['Foo']; > > my $obj = Inline::Struct::Foo->new; > $obj->num(10); > $obj->str("Hello"); > > myfunc($obj); > > __END__ > __C__ > > struct Foo { > int num; > char *str; > }; > > void myfunc(Foo *f) { > printf("myfunc: num=%i, str='%s'\n", f->num, f->str); > } > > OUTPUT : I get the following error > > Can't locate object method "new" via package "Inline::Struct::Foo" > (perhaps you forgot to load "Inline::Struct::Foo"?) at temp2.pl line 1. > I think you need to write it in a different format. (Even though that example is from the docs, I get exactly the same output as you.) The following rewrite works fine for me, however: ------------------------- use Inline C => <<'EOC', STRUCTS => 1; struct Foo { int num; char *str; }; typedef struct Foo Foo; void myfunc(Foo *f) { printf("myfunc: num=%i, str='%s'\n", f->num, f->str); } EOC my $obj = Inline::Struct::Foo->new; $obj->num(10); $obj->str("Hello"); myfunc($obj); ------------------------ All I've done there is just re-arrange the layout (which is the same as occurs in the Inline::Struct test files). And I also had to stick in the 'typedef struct Foo Foo;' Cheers, Rob