foreign handlers

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

foreign handlers

Post by monte » Sat Sep 12, 2015 3:18 am

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
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: foreign handlers

Post by monte » Sat Sep 12, 2015 3:23 am

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?
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: foreign handlers

Post by LCMark » Tue Sep 15, 2015 8:50 am

@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!).

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: foreign handlers

Post by monte » Wed Sep 16, 2015 12:29 am

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.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: foreign handlers

Post by [-hh] » Fri Sep 18, 2015 12:25 pm

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?
shiftLock happens

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: foreign handlers

Post by LCMark » Fri Sep 18, 2015 6:17 pm

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.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: foreign handlers

Post by [-hh] » Fri Sep 18, 2015 7:56 pm

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.
shiftLock happens

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: foreign handlers

Post by jacque » Sat Sep 19, 2015 4:44 pm

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"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: foreign handlers

Post by [-hh] » Sat Sep 19, 2015 8:47 pm

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" ...
shiftLock happens

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: foreign handlers

Post by LCMark » Tue Sep 22, 2015 12:28 pm

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.

Post Reply

Return to “LiveCode Builder”