1

In Pike, it is possible to retrieve all members of an object by calling indices(). Is it also possible to see all members of a class without instantiating it?

> class A {int foo; string bar;};
> A a = A();
> indices(a);
(1) Result: ({ /* 2 elements */
                "foo",
                "bar"
            })
> indices(A);
(2) Result: ({ })

1 Answers1

1

Yes, you can, although output won't be as friendly as indices one. You need to use _describe_program function, like this:

> _describe_program(A);
(4) Result: ({ /* 2 elements */
            ({ /* 7 elements */
                0,
                "foo",
                int,
                0,
                0,
                0,
                0
            }),
            ({ /* 7 elements */
                0,
                "bar",
                string,
                0,
                16,
                0,
                0
            })
        })
grodzik
  • 264
  • 3
  • 10
  • 1
    Thank you! It is also worth pointing out that calling `indices()` on a class/program returns its constant members (this is not documented though): `> class A { constant nono = 0; } > indices(A); (9) Result: ({ /* 1 element */ "nono" }) ` – turbowarkocz Jan 10 '19 at 13:12