slang-users mailing list

[2021 Date Index] [2021 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Re: How to handle a variable reference passed to a C function?


I couldn't resolve the problem and I've found following mention in
slirp-…/examples/kitchensink/test.sl (line 80) that C-side fetching of an
input reference variables is not supported:

% The next call attempts a NULL ptr reference, since the public S-Lang C api
% doesn't provide a way of dereferencing (obtaining the value of) a S-Lang
ref

So I've went a different path – #argmap(out) one parameter so that the
function returns 2 values, and also use a normal (not reference) parameter
pass in value. So the call now looks like:

variable start_search_pos = 5;
(str, position) = afunc(start_search_pos, DIRECTION_LEFT);

and it's a better solution than the original, because the "start_search_pos"
isn't exactly the same as the "start_pos" that's being returned – the
function looks for a adjacent word at given position and in given
direction, and it returns the starting position of the found word.

So the API is now cleaner :)

BTW. thanks for creating Slirp and S-Lang :)


On Thu, 22 Jul 2021 at 09:42, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
wrote:

> Hi,
> I want to have additional out parameters for a function, so I do:
>
> variable in1=1, in2=2, in3out = 3'
> afunc(in1,in2,&in3out);
>
> Then, on the C side I do:
>
> void afunc(long in1, long in2, long *in3out)
> {
>     log("inout parameter holds value %li", *in3out);
> }
>
> And generate the glue code via slirp.
>
> However, the value printed by log() function / passed to the function by
> the third, pointer parameter is 0. Why?
>
> --
> Best regards,
> Sebastian Gniazdowski
>


-- 
Best regards,
Sebastian Gniazdowski

[2021 date index] [2021 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]