poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] Convention for multi-line pretty-printed output


From: Dan Čermák
Subject: Re: [RFC] Convention for multi-line pretty-printed output
Date: Sun, 03 May 2020 12:30:42 +0200

"Jose E. Marchesi" <address@hidden> writes:

>
> All you have to do is to add a method called _print to your struct type,
> that should get no arguments and should return no value.

Hm, speaking of this: wouldn't it be handy to have the _print function
return the formatted string instead of printing it directly? This could
be useful for (probably) a number of things, but of the top of my head I
guess it could be useful for nested structs (i.e. a struct Foo has a
member struct Bar, Bar already has a pretty printer, and then Foo could
pretty print itself and potentially mess with Bar's output or just
wouldn't have to call printf multiple times).

> When the user
> has pretty-print set to `yes' (I have that setting in my .pokerc file)
> then _print will be called to obtain the textual representation of
> values of that struct.
>
> Example:
>
> deftype BPF_Reg =
>   struct
>   {
>    uint<4> code;
>
>    defun _print = void:
>    {
>     print "#<";
>     if (code < BPF_R9)
>       printf "%<insn-register:%sr%i32d%>", "%", code;
>     else
>       printf "%<insn-register:fp%>";
>     print ">";
>    }
>   };
>
> Note how this pretty printer uses the #<> convention, and also uses
> styling classes.

Thank you for this example!


Cheers,

Dan

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]