Hi,
I'm experimenting with calls from M to C but my C-experience is very small.
I've done this:
S VAR1="BCB",VAR2="DEF"
D &test.hello(VAR1,VAR2)
test.xc:
/home/aut/test.so
hello: ydb_status_t hello(I:ydb_string_t* ,I:ydb_string_t* )
test.c:
#include <stdio.h>
#include "libyottadb.h"
int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
{
printf("\nHello\n");
printf("\n");
printf("%s%d", "\nLength 1 ", stringA.length);
printf("%s%d", "\nLength 2 ", stringB.length);
printf("%s%d", "\nArguments ", argc);
printf("%s%s", "\nText 1 ", stringA.address);
printf("%s%s", "\nText 2 ", stringB.address);
return 0;
}
Result:
Hello
Length 1 2073116
Length 2 3
Arguments 2
Text 1
Text 2 BCBDEF
Why is the first length incorrect and the first text not shown?
Can anyone help?
Does anyone have an example with parameter transfer from an to M?
Jens
Sam, Thank you for your hints. The zlib-example helped me much. If there was a link to this C-code in the documentation it would be a help for others too I guess.
Jens
One extended question to this topic:
If I call the C-subroutine like this:
D &test.hello(VAR1,.VAR2)
int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
Is it possible to send back an array to VAR2?
I know about ydb_set_s(), but the C-program doesn't know the name "VAR2" to add nodes to it.
Jens
One extended question to this topic:Jens,
If I call the C-subroutine like this:
D &test.hello(VAR1,.VAR2)
int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
Is it possible to send back an array to VAR2?
I know about ydb_set_s(), but the C-program doesn't know the name "VAR2" to add nodes to it.
Jens
On Friday, June 18, 2021 at 6:25:03 AM UTC-6, Jens wrote:
One extended question to this topic:
If I call the C-subroutine like this:
D &test.hello(VAR1,.VAR2)
int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
Is it possible to send back an array to VAR2?
I know about ydb_set_s(), but the C-program doesn't know the name "VAR2" to add nodes to it.
JensJens,
I don't think that's possible. Back when I wrote this: https://github.com/shabiel/fis-gtm-plugins/blob/master/libcurl/libcurl_ydb_wrapper.c, I wish I could do that for GT.M code, but I couldn't; and I ran up against the limit for strings.
If you can't provide a delimited output that can be parsed back by M into an array, you will have to use ydb_set_s. It is somewhat difficult to use. You can send out the variable you would like to set in stringB, and use it.
I wrote this recently for my job: https://gitlab.com/shabiel/YDBAIM/-/blob/ydbaim-c-api/ydbaim.c#L109
You can read there exactly how to do what you want.
--Sam
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 66:06:10 |
Calls: | 6,654 |
Files: | 12,200 |
Messages: | 5,331,879 |