Task

The goal is to get the properties of an object, as names, values or both.

Some languages support dynamic properties, which in general can only be inspected if a class' public API includes a way of listing them.

class c nullable
    integer int = 1
    public atom atm = 2.3
    string str = "4point5"
    sequence seq
  public:
    object obj = {"an object"}
    c child
    private function foo();
    public procedure bar();
end class
 
c c_instance = new()
 
include builtins\structs.e as structs
function nulls(object s) return iff(s=NULL?"NULL":s) end function
sequence fields = structs:get_struct_fields(c)
for i=1 to length(fields) do
    {string name, integer tid, integer flags} = fields[i]
    if not and_bits(flags,SF_RTN) then -- (exclude foo/bar)
        string t = nulls(structs:get_field_type(c,name,true)),
               f = nulls(structs:get_field_flags(c,name,true))
        object v = nulls(structs:fetch_field(c_instance,name,c))
        printf(1,"type:%-11s,  name:%-5s,  flags:%s, value:%v\n",{t,name,f,v})
    end if
end for
