kerep/src/kprint
2023-01-16 00:04:28 +06:00
..
kprint_colors.h fixed one typo 2022-10-30 18:51:49 +06:00
kprint_format.h yet another ktid type system refactoring 2022-11-04 22:19:19 +06:00
kprint_format.md Merge branch 'main' of https://github.com/Timerix22/kerep 2022-11-05 13:10:06 +06:00
kprint.c Merge branch 'main' of https://github.com/Timerix22/kerep 2022-11-05 13:10:06 +06:00
kprint.h all printf calls replaced with kprintf 2022-10-24 18:33:43 +06:00
kprintf.c semicolons after case: 2023-01-16 00:04:28 +06:00
kprintf.h all printf calls replaced with kprintf 2022-10-24 18:33:43 +06:00
README.md yet another ktid type system refactoring 2022-11-04 22:19:19 +06:00

kprintf

It is just my variant of printf.

kprint

I don't really like printf function (and its variants), so i made safer and more convinient replacement.

function returns arguments
kprint void/throw kprint_format, void*, kprint_format, void*...
ksprint Maybe<char*> kprint_format, void*, kprint_format, void*...
kfprint Maybe FILE*, kprint_format, void*, kprint_format, void*...

how to use it:

  • format construction:

    kprint_format fmt= kprint_fgColor | kprint_bgColor | kprint_fdataFmt | flags | ktid;
    

    more about kprint_format

    • fgColor and bgColor can be set to change console output color
    • you should set dataFormat for int/uint/float/char* arguments and ktid for other types
    • flags can be set to modify TypeDescriptor.toString() behavior
    • don't forget to set TypeDescriptor.toString when registering type, or kprint will crash
  • using base type arguments:
    you can just put them into a function

    kprint(kprint_fmtHex | kprint_fmtUppercase | kprint_fmtWithPrefix, 255);
    

    output: 0xFF

  • using other registered types:
    should be sent as pointers

    Maybe m=MaybeNull;
    kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktid_MaybePtr, &m);
    

    output: Maybe: {value={0, ktid_Null}}