C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany


Post by Tetraeder » Thu Dec 10, 2015 7:50 am

Hello, it's me :D
In needed in my project a function with four arguments. So I got the definition added to obj.h and objfunc.c.
maybe it needed someone else also.
Perhaps also an opportunity: to defined dynamically function for x arguments.
Just as a note.

Site Admin
Posts: 634
Joined: Mon Dec 09, 2013 5:02 pm


Post by Damien » Thu Dec 10, 2015 5:18 pm

For 4 or more arguments (or a varying number of arguments) you should use the MP_DEFINE_CONST_FUN_OBJ_VAR or MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN macros. Eg, for 4 args it could be:

Code: Select all

STATIC mp_obj_t mp_func_with_4_args(mp_uint_t n_args, const mp_obj_t *args) {
    (void)n_args; // unused, we know it's 4
    // args[0], args[1], args[2], args[3] contain the 4 arguments
    // do processing...
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(my_func_with_4_args_obj, 4, 4, my_func_with_4_args);

Post Reply