deshipu / micropython-dev-docs

Documentation on how to develop C modules for MicroPython
15 stars 17 forks source link

Use mp_printf instead of printf #4

Open amirgon opened 6 years ago

amirgon commented 6 years ago

on "adding-module":

STATIC void mymodule_hello_print( const mp_print_t *print,
                                  mp_obj_t self_in,
                                  mp_print_kind_t kind ) {
    // get a ptr to the C-struct of the object
    mymodule_hello_obj_t *self = MP_OBJ_TO_PTR(self_in);
    // print the number
    printf ("Hello(%u)", self->hello_number);
}

Should be something like:

STATIC void mymodule_hello_print( const mp_print_t *print,
                                  mp_obj_t self_in,
                                  mp_print_kind_t kind ) {
    // get a ptr to the C-struct of the object
    mymodule_hello_obj_t *self = MP_OBJ_TO_PTR(self_in);
    // print the number
    mp_printf (print, "Hello(%u)", self->hello_number);
}