Skip to content

Custom functions in micropython #1791

Answered by Redstonetill
Redstonetill asked this question in Q&A
Discussion options

You must be logged in to vote

Since it is a search algorithem (A*) on f...ing huge graph there isn't any other way but to code it in C, but the approach with the "pb_module_tools.c" really help, and I have a simple function that just adds to numbers. This is the code I have added to the "pb_module_tools.c" if anyone would need it in the future:

This code at line 347

static mp_obj_t pb_module_tools_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) {
   int a = mp_obj_get_int(a_obj);
   int b = mp_obj_get_int(b_obj);
   return mp_obj_new_int(a + b);
}
static MP_DEFINE_CONST_FUN_OBJ_2(pb_module_tools_add_ints_obj, pb_module_tools_add_ints);

And this code into the "tools_globals_table[]" Array (the array is now at 360):

{ MP_ROM_QSTR

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Redstonetill
Comment options

Answer selected by Redstonetill
@Redstonetill
Comment options

@dlech
Comment options

@Redstonetill
Comment options

@dlech
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants