If you are asking a question, please follow this template:
My goal is: [describe your goal]
to link a C function to MJS
My actions are: [describe your actions - code, commands, etc]
let rxAcc = ‘’; // Accumulated Rx data
let start;
let finish;
let getMsg=ffi(‘int get_msg(char *,int,int *,int *)’);
let ret=getMsg(rxAcc, rxAcc.length, &start, &finish);
C routine: int get_msg(char *buffer, int len, int *start, int *finish)
The result I see is: [show the result - log, etc]
MJS error: parse error at line 92: [&start, &f]
My expectation & question is: [describe your expectation and your question]
getting the values for ret, start and finish returned to the MJS code
In the mJS code use Sys.malloc to allocate start and finish, pass the pointers to your function,
create a Dataview for each pointer, get the value and finally Sys.free the pointers.
It’s possible to use another approach if you replace the start and finish parameters with a pointer to a structure. In this case Converting structs to objects is to be used.
I see this ‘assuming’ in the MJS document [https://github.com/cesanta/mjs],
how do I get it into my MJS code assuming it exists in my C code?
// Assuming s is a foreign pointer to an instance of my_struct, obtained elsewhere.
let sd = ffi(‘void *get_my_struct_descr(void)’)();
let o = s2o(s, sd);
print(o.a, o.b);