Livecode Builder - passing lcs string to C functions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Livecode Builder - passing lcs string to C functions

Rick Harrison via use-livecode
Hi I'm stuck trying to find examples of passing lcs strings to a C function
via pointer and it's driving me mad! I can retrieve char * pointers from C
functions, convert to string and pass back to lcs but haven't come across
any easy to grok examples of sending data to C. Any guidance would be
appreciated

Thanks

Dan
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Livecode Builder - passing lcs string to C functions

Rick Harrison via use-livecode
Basically you just use a shell  command to execute the c code
and  pass arguments to  the c program right after you call the
code  in the shell command.

I  wrote and example and posted it a few years ago  but I do
not have access to my old email  files at the moment but you
might still  be able to  find it by searching the list.

I would be interested in seeing how you are doing it if you
ever want to post the code for others to use.

JB


> On Dec 28, 2020, at 5:02 AM, Dan Brown via use-livecode <[hidden email]> wrote:
>
> ´╗┐Hi I'm stuck trying to find examples of passing lcs strings to a C function
> via pointer and it's driving me mad! I can retrieve char * pointers from C
> functions, convert to string and pass back to lcs but haven't come across
> any easy to grok examples of sending data to C. Any guidance would be
> appreciated
>
> Thanks
>
> Dan
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Livecode Builder - passing lcs string to C functions

Rick Harrison via use-livecode
In reply to this post by Rick Harrison via use-livecode
On Mon, Dec 28, 2020 at 7:02 AM Dan Brown via use-livecode <
[hidden email]> wrote:

> Hi I'm stuck trying to find examples of passing lcs strings to a C function
> via pointer and it's driving me mad! I can retrieve char * pointers from C
> functions, convert to string and pass back to lcs but haven't come across
> any easy to grok examples of sending data to C. Any guidance would be
> appreciated


I've used MCStringConvertToBytes to convert strings to a value you can pass
in as const char*. I have a hunspell example you can reference.

Here is a link to the Hunspell_spell definition:

https://github.com/hunspell/hunspell/blob/8a2fdfe5a6bb1cbafc04b0c8486abcefd17ad903/src/hunspell/hunspell.h#L69

```
LIBHUNSPELL_DLL_EXPORTED int Hunspell_spell(Hunhandle* pHunspell, const
char*);
```

Here is a link to the LCB code that passes a UTF8 string to Hunspell_spell:

https://github.com/trevordevore/lc-hunspell/blob/master/hunspell.lcb#L150

Here is a link to the MCStringConvertToBytes definition in the LCB file:

https://github.com/trevordevore/lc-hunspell/blob/master/hunspell.lcb#L19

--
Trevor DeVore
ScreenSteps
www.screensteps.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Livecode Builder - passing lcs string to C functions

Rick Harrison via use-livecode
Thanks so much for this Trevor, I can now retrieve requests from and
respond to a virtual threaded http server which is nice. Now trying to work
out how not to block the engine when the function that calls the server
waits for a new request to come in i..e callback functions purely within
lcb

Dan



On Mon, Dec 28, 2020 at 10:09 PM Trevor DeVore via use-livecode <
[hidden email]> wrote:

> On Mon, Dec 28, 2020 at 7:02 AM Dan Brown via use-livecode <
> [hidden email]> wrote:
>
> > Hi I'm stuck trying to find examples of passing lcs strings to a C
> function
> > via pointer and it's driving me mad! I can retrieve char * pointers from
> C
> > functions, convert to string and pass back to lcs but haven't come across
> > any easy to grok examples of sending data to C. Any guidance would be
> > appreciated
>
>
> I've used MCStringConvertToBytes to convert strings to a value you can pass
> in as const char*. I have a hunspell example you can reference.
>
> Here is a link to the Hunspell_spell definition:
>
>
> https://github.com/hunspell/hunspell/blob/8a2fdfe5a6bb1cbafc04b0c8486abcefd17ad903/src/hunspell/hunspell.h#L69
>
> ```
> LIBHUNSPELL_DLL_EXPORTED int Hunspell_spell(Hunhandle* pHunspell, const
> char*);
> ```
>
> Here is a link to the LCB code that passes a UTF8 string to Hunspell_spell:
>
> https://github.com/trevordevore/lc-hunspell/blob/master/hunspell.lcb#L150
>
> Here is a link to the MCStringConvertToBytes definition in the LCB file:
>
> https://github.com/trevordevore/lc-hunspell/blob/master/hunspell.lcb#L19
>
> --
> Trevor DeVore
> ScreenSteps
> www.screensteps.com
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode