Page 1 of 1

foreign handlers

Posted: Sat Sep 12, 2015 3:18 am
by monte
Hi

I've had an initial play with LCB foreign handlers binding to native code and can't seem to get it to work. Here's my code:

https://github.com/livecode/livecode/co ... _extension

The bind string must be wrong but I tried the following and all failed:
  • libyaml-0.2>yaml_get_version_string
  • yaml-0.2>yaml_get_version_string
  • libyaml-0.2>yaml_get_version_string()
I get this error when I try LibYAMLVersion() in the message box

Code: Select all

Message execution error:
Error description: extension: error occured with domain
Hint: runtime
So... a bit confused about what the problem might be. Any clues would be welcome.

Also @LCMark it's probably better to answer that question about structs over here. I'm guessing the simplest thing for me to do would be to wrap the library to avoid them.

Cheers

Monte

Re: foreign handlers

Posted: Sat Sep 12, 2015 3:23 am
by monte
Hmm... I just realised the problem could be that I'm passing a ZStringNative to DecodeUTF8 instead of Data. Or does the compiler handle the conversion?

Re: foreign handlers

Posted: Tue Sep 15, 2015 8:50 am
by LCMark
@monte: That could well be the problem. Things like ZStringNative and such need to be used with care as they aren't quite correct yet. You are better off binding your foreign handlers with 'pointer' at the moment and then writing shims in LCB. There's memory ownership problems with things like ZStringNative (they are okay for 'in' parameters, and out / results when the callee passes ownership of the underling memory buffer back to the caller; otherwise they will cause nastiness!).

Re: foreign handlers

Posted: Wed Sep 16, 2015 12:29 am
by monte
Hmm... that sounds interesting... I guess I have some reading to do in order to work out how to get a Data variable from a pointer. I guess there's something I can bind to in the engine to do that. I had thought that this function would be about as simple as it could get with it just returning a const char * and all.. There's a version that sets three referenced ints so I'll try that as a test and go from there.

Re: foreign handlers

Posted: Fri Sep 18, 2015 12:25 pm
by [-hh]
Is there any docu on com.livecode.foreign?
Or more specific, is there any docu on how to use C/C++/Cocoa libraries in LCB?

Re: foreign handlers

Posted: Fri Sep 18, 2015 6:17 pm
by LCMark
Not yet :) It is still a bit of a black-art as the features for it in LCB are still very immature. It is high on the list to give some more attention to though.

Re: foreign handlers

Posted: Fri Sep 18, 2015 7:56 pm
by [-hh]
Thanks.

As I'm not a native speaker I looked for the meaning before misunderstandig it.
There are 19 possible references on

https://en.wikipedia.org/wiki/Black_art

for "black-art".
Hopefully you don't refer to one, that some of us may not agree with.

Re: foreign handlers

Posted: Sat Sep 19, 2015 4:44 pm
by jacque
I don't see anything in that list that really applies here. If you search Google for "what is black art" the default definition is the humorous one he was using.

humorous
a technique or practice considered mysterious and sinister.
"the black art of political news management"

Re: foreign handlers

Posted: Sat Sep 19, 2015 8:47 pm
by [-hh]
Humorous -- yes, but perhaps it is black humour alike Monty Python's Flying Circus?
A library for handling non-Scotswomen/non-Scotsmen, you and me too?
Don't forget this library is called "com.livecode.foreign" ...

Re: foreign handlers

Posted: Tue Sep 22, 2015 12:28 pm
by LCMark
Haha - yes - I'm surprised the wikipedia page doesn't directly refer to what is a common usage (in Britain at least). Describing something as a 'black-art' usually refers to it being 'arcane' - nothing sinister, just requiring more knowledge / experience than you might expect or more details which you can find information about easily.