Re: [Chicken-users] more 'foreign' questions
Thanks! This all works now, and I learned a lot. I now get a void pointer to some data in memory, and the length of the > payload. How can I make that e.g. a blob? Or a string? > > we’re trying to stop using string for non-char data so blob please ;-) > Sorry. Didn't want to frighten you ;-) I almost always have strings in there (JSON), that's why I asked. ... but when I put everything together, hope it will end up as a new egg, I'll surely return the blob, so that people can decide freely. ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] more 'foreign' questions
Awesome, thanks! Will try. Have a good flight! On Wed, Mar 27, 2019 at 8:19 PM Kon Lovett wrote: > (gotta flight coming up so dashing but hth) > > probably need to use the length for make-blob & then move-memory! from > pointer to the alloc’ed blob > > see (chicken memory) > > > On Mar 27, 2019, at 12:14 PM, Christoph Lange > wrote: > > > > i haven’t used the bind egg but the documentation "General Operation” > section beginining with "Structure and union definitions …” seems relevant. > > > > Haha, yes, thanks. Finding the relevant parts of the docs seems to be > the challenge in the beginning. Will read that. > > > > it rolls access routines, ex: mosquitto_message-mid, > mosquitto_message-payload, ... > > > > > > #;1> (import bind) > > #;2> ,x* (bind* "struct mosquitto_message{ > > int mid; > > char *topic; > > void *payload; > > int payloadlen; > > int qos; > > ___bool retain; > > };”) > > > > Oh, useful tool to learn, as it seems. > > > > Thanks for the help. ... one follow-up question: > > > > I now get a void pointer to some data in memory, and the length of the > payload. How can I make that e.g. a blob? Or a string? > > -- Christoph Lange Lotsarnas Väg 8 430 83 Vrångö ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] more 'foreign' questions
> On Mar 27, 2019, at 12:14 PM, Christoph Lange wrote: > > i haven’t used the bind egg but the documentation "General Operation” > section beginining with "Structure and union definitions …” seems relevant. > > Haha, yes, thanks. Finding the relevant parts of the docs seems to be the > challenge in the beginning. Will read that. > > it rolls access routines, ex: mosquitto_message-mid, > mosquitto_message-payload, ... > > > #;1> (import bind) > #;2> ,x* (bind* "struct mosquitto_message{ > int mid; > char *topic; > void *payload; > int payloadlen; > int qos; > ___bool retain; > };”) > > Oh, useful tool to learn, as it seems. the expand-full egg (only for macro debugging really) > > Thanks for the help. ... one follow-up question: > > I now get a void pointer to some data in memory, and the length of the > payload. How can I make that e.g. a blob? Or a string? we’re trying to stop using string for non-char data so blob please ;-) ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] more 'foreign' questions
(gotta flight coming up so dashing but hth) probably need to use the length for make-blob & then move-memory! from pointer to the alloc’ed blob see (chicken memory) > On Mar 27, 2019, at 12:14 PM, Christoph Lange wrote: > > i haven’t used the bind egg but the documentation "General Operation” > section beginining with "Structure and union definitions …” seems relevant. > > Haha, yes, thanks. Finding the relevant parts of the docs seems to be the > challenge in the beginning. Will read that. > > it rolls access routines, ex: mosquitto_message-mid, > mosquitto_message-payload, ... > > > #;1> (import bind) > #;2> ,x* (bind* "struct mosquitto_message{ > int mid; > char *topic; > void *payload; > int payloadlen; > int qos; > ___bool retain; > };”) > > Oh, useful tool to learn, as it seems. > > Thanks for the help. ... one follow-up question: > > I now get a void pointer to some data in memory, and the length of the > payload. How can I make that e.g. a blob? Or a string? ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] more 'foreign' questions
> > i haven’t used the bind egg but the documentation "General Operation” > section beginining with "Structure and union definitions …” seems relevant. > Haha, yes, thanks. Finding the relevant parts of the docs seems to be the challenge in the beginning. Will read that. it rolls access routines, ex: mosquitto_message-mid, > mosquitto_message-payload, ... > #;1> (import bind) > #;2> ,x* (bind* "struct mosquitto_message{ > int mid; > char *topic; > void *payload; > int payloadlen; > int qos; > ___bool retain; > };”) > Oh, useful tool to learn, as it seems. Thanks for the help. ... one follow-up question: I now get a void pointer to some data in memory, and the length of the payload. How can I make that e.g. a blob? Or a string? > ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] more 'foreign' questions
i haven’t used the bind egg but the documentation "General Operation” section beginining with "Structure and union definitions …” seems relevant. it rolls access routines, ex: mosquitto_message-mid, mosquitto_message-payload, ... #;1> (import bind) ; loading /usr/local/chicken/5/lib/chicken/10/bind.import.so ... ; loading /usr/local/chicken/5/lib/chicken/10/chicken.foreign.import.so ... ; loading /usr/local/chicken/5/lib/chicken/10/bind-translator.so ... ; loading /usr/local/chicken/5/lib/chicken/10/matchable.so ... ; loading /usr/local/chicken/5/lib/chicken/10/bind.so ... #;2> ,x* (bind* "struct mosquitto_message{ int mid; char *topic; void *payload; int payloadlen; int qos; ___bool retain; };”) (##core#begin (##core#declare (foreign-declare "#define ___fixnum int\n#define ___number double\n#define ___bool int\n#define ___byte char\n#define ___scheme_value C_word\n#define ___scheme_pointer void *\n#define ___blob void *\n#define ___pointer_vector void **\n#define ___symbol char *\n#define ___safe\n#define ___declare(x, y)\n#define ___specialize\n#define ___abstract\n#define ___discard\n#define ___in\n#define ___out\n#define ___inout\n#define ___mutable\n#define ___length(var)\n#define ___pointer\n#define ___u32 C_u32\n#define ___s32 C_s32\n#define ___u64 C_u64\n#define ___s64 C_s64" "struct mosquitto_message{\n int mid;\n char *topic;\n void *payload;\n int payloadlen;\n int qos;\n ___bool retain;\n};" "\n")) (##core#begin (##core#begin (##core#ensure-toplevel-definition mosquitto_message-mid) (##core#set! mosquitto_message-mid (foreign-lambda* integer (((c-pointer (struct "mosquitto_message")) s)) "return(s->mid);"))) (##core#begin (##core#ensure-toplevel-definition mosquitto_message-topic) (##core#set! mosquitto_message-topic (foreign-lambda* c-string (((c-pointer (struct "mosquitto_message")) s)) "return(s->topic);"))) (##core#begin (##core#ensure-toplevel-definition mosquitto_message-payload) (##core#set! mosquitto_message-payload (foreign-lambda* (c-pointer void) (((c-pointer (struct "mosquitto_message")) s)) "return(s->payload);"))) (##core#begin (##core#ensure-toplevel-definition mosquitto_message-payloadlen) (##core#set! mosquitto_message-payloadlen (foreign-lambda* integer (((c-pointer (struct "mosquitto_message")) s)) "return(s->payloadlen);"))) (##core#begin (##core#ensure-toplevel-definition mosquitto_message-qos) (##core#set! mosquitto_message-qos (foreign-lambda* integer (((c-pointer (struct "mosquitto_message")) s)) "return(s->qos);"))) (##core#begin (##core#ensure-toplevel-definition mosquitto_message-retain) (##core#set! mosquitto_message-retain (foreign-lambda* bool (((c-pointer (struct "mosquitto_message")) s)) "return(s->retain);"))) (##core#begin (##core#ensure-toplevel-definition make-mosquitto_message) (##core#set! make-mosquitto_message (foreign-lambda* (c-pointer (struct "mosquitto_message")) ((integer mid) (c-string topic) ((c-pointer void) payload) (integer payloadlen) (integer qos) (bool retain)) "struct mosquitto_message *tmp_ = (struct mosquitto_message *)C_malloc(sizeof(struct mosquitto_message));\ntmp_->mid = mid;\ntmp_->topic = topic;\ntmp_->payload = payload;\ntmp_->payloadlen = payloadlen;\ntmp_->qos = qos;\ntmp_->retain = retain;\nreturn(tmp_);;\n") > On Mar 27, 2019, at 8:06 AM, Christoph Lange wrote: > > After I now managed quite a lot of my interfacing to the mqtt library, I'm > stuck with the following: > > I have the following definition of a message struct, which I in fact get > back a pointer to, from a callback: > > (bind* "struct mosquitto_message{ > int mid; > char *topic; > void *payload; > int payloadlen; > int qos; > ___bool retain; > };") > > When I print what I get in Scheme it says something along the line of > #. Though the library frees the memory, it will -- > according to manual -- only do so after the callback returns. So within the > callback, I should be able to access / print it's content. Just how?! How do > I access the different fields in that struct? Especially the payload? > > /Christoph > ___ > Chicken-users mailing list >
[Chicken-users] more 'foreign' questions
After I now managed quite a lot of my interfacing to the mqtt library, I'm stuck with the following: I have the following definition of a message struct, which I in fact get back a pointer to, from a callback: (bind* "struct mosquitto_message{ int mid; char *topic; void *payload; int payloadlen; int qos; ___bool retain; };") When I print what I get in Scheme it says something along the line of #. Though the library frees the memory, it will -- according to manual -- only do so after the callback returns. So *within* the callback, I should be able to access / print it's content. Just *how*?! How do I access the different fields in that struct? Especially the payload? /Christoph ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users