Passing variables between C and Python

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
SpotlightKid
Posts: 334
Joined: Wed Apr 08, 2015 5:19 am

Re: Passing variables between C and Python

Post by SpotlightKid » Wed May 11, 2016 3:23 pm

Perhaps it would be helpful if you explained with a bit more detail what your usage scenario is and what you are trying to accomplish. Then we wouldn't have to talk in such general terms and maybe give more concrete help.

cduran
Posts: 44
Joined: Thu Mar 17, 2016 4:52 pm

Re: Passing variables between C and Python

Post by cduran » Thu May 04, 2017 12:02 am

I want to pass a python list to my c callback:

Code: Select all

static mp_obj_t c_sample_call_callback(mp_obj_t mpOpcode, mp_obj_t mp_arg1, mp_obj_t mp_arg2)
I've been using mp_obj_new_bytearray() to go from a c array to a python list, but I would like to know what the function is to go from a python list to a c array.

User avatar
dhylands
Posts: 2821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: Passing variables between C and Python

Post by dhylands » Thu May 04, 2017 4:06 am

A python list is just an mp_obj_t.

The C code would then call mp_obj_list_get to get the length of the list and a pointer to an array of mp_obj_t's for each element in the list.

Post Reply