Re: Problem with cmods

Chris Angelico <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <CAPTjJmpj1hNoW5-vqr_o=JPMpLL6X6Xpg2Q9V2tYrK9JU51jFQ@mail.gmail.com>
On Tue, Mar 25, 2014 at 5:28 PM, Christian Toepp <[email protected]> wrote:
> Hi, i have a little problem with cmods. i write
>
> --SNIP--
> PIKECLASS PikeTest{
>   PIKEFUN string func(string mystring){
>     struct pike_string *foo = make_shared_string("foo");
>     pop_n_elems(args);
>     push_string(foo);
>   }
> }
> --SNIP--
>
> it compiles without problems but if i try to call these function like
>
> write(PikeTest.func("foo"));
>
> i get the message "Index 'func' not present in module 'PikeTest'"
>
> whats wrong with my code?

What you've done there is create a class named PikeTest, and if that's
in PikeTest.cmod, you'll have a class called PikeTest.PikeTest. Try
instantiating that:

write(PikeTest.PikeTest()->func("foo"));

Seems wordy at first, but gets handy when you need to retain state.

ChrisA
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.