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
n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Foreign handlers

Post by n.allan » Mon Mar 16, 2015 12:38 am

I am having great results so far with libraries and widgets. i am just skimming over some of the features as part of my learing process.

Would it be possible for someone to post an example of a "foreign" handler calling a c library? Along with an example of binding to a library.

My main platform is windows where normally one would import lib and or use headers in c++ to call a library.

Skimming the help docs, i simply cannot see the direction LCB will take to do this on windows.

I hear calling libraries is a lot simpler on osx/linux but I don't have much experience with those oses.

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

Re: Foreign handlers

Post by LCMark » Mon Mar 16, 2015 9:42 am

@n.allan: At present the 'foreign handler' mechanism we have is quite basic in that it doesn't do much to help transform from LCB types to low-level (foreign) types beyond the basic ones (pointer, boolean, integer, real). However, that being said, the same formalism is used on all platforms - the only difference with Windows is that the WIn32 ABI has a zoo of calling conventions (the Win64 ABI does not). However, essentially that just comes down to an extra annotation in the binding string.

Despite its immaturity you can still do a fair bit with the foreign handler interface as it is now - I'll see if I can work up a WIn32 example today to give you an idea about how to go about playing around with the feature.

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Foreign handlers

Post by n.allan » Mon Mar 16, 2015 10:40 am

Great! I am no where near the point of using them in anger yet, but just a taste of how it will work would be good before I continue my initial prodding.

mdoub
Posts: 14
Joined: Sun Jan 07, 2007 5:47 pm

Re: Foreign handlers

Post by mdoub » Sun Mar 22, 2015 9:29 pm

@ Mark

I am also interested in the taking advantage of the ability to build wrappers to get access to native libraries. Can you elaborate a bit on how this is envisioned to work at the architectural level. I think I see what you are trying to do at the language level with the data type bindings. What is the mechanism to locate and load the foreign library? Are language elements going to be added to load and remove libraries or are they going to be static.

Thanks
Mike

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

Re: Foreign handlers

Post by LCMark » Tue Mar 24, 2015 10:42 am

@mdoub: You're post on the use list was an accurate assessment of the current implementation of the foreign mechanism. Indeed, most LCB syntax is implemented as foreign handlers. Currently foreign handler bindings occur the first time (at runtime) the handler is used and the VM uses the binding string to locate the symbol. We need to do more work here but if you dig into the script-instance.cpp source file you can see its current syntax... Only C binding is implemented at the moment - and it still needs some work :)

You'll be able to access both system libraries and private libraries you've compiled yourself and included in the extensions package. We're still working on the latter though.

mdoub
Posts: 14
Joined: Sun Jan 07, 2007 5:47 pm

Re: Foreign handlers

Post by mdoub » Tue Mar 24, 2015 2:33 pm

Thanks Mark. I figured that it was still very early in the implementation and this is one of the more complicated areas.

I do think that you are going need a mechanism to allow the user to specify the path to the desired library. It might be reasonable to make assumptions of the locations of the system libraries, but you are going to need more flexibility for optionally installed packages. You may even need to allow this to be set up in LCB dynamically. What has got me thinking this way is considering testing an app against multiple versions of the same server component. Each version has libraries installed in it's own directory.

Anyway, keep up the good work! This is great stuff.

-= Mike

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

Re: Foreign handlers

Post by LCMark » Mon Mar 30, 2015 9:07 am

@mdoub: Our current imagining of 'foreign handler' support is that you either bind to libraries which exist on the system already, or to compiled blobs which are within a module's package (and are private to it). All OSes provide suitable means to set the library path search order for the former, whilst the latter would be entirely controlled by the engine / standalone build process.

In terms of truly 'dynamic' access - i.e. loading a shared library at runtime and then dynamically looking up a handler explicitly at that point - then that it is almost covered by LCB's current functionality; the only bit missing is the ability to create an LCB handler value out of an arbitrary pointer. With the latter functionality you could just bind to 'dlopen', and 'dlsym' as foreign handlers and create a handler value out of the result of 'dlsym'.

The way handler values are set up in LCB means that they are all (notionally) of type 'handler', but you have to place them in a specific handler-type variable before being able to use them (since the compiler needs to know the signature ahead-of-time so it can compile in/out/inout arguments correctly).

Post Reply

Return to “LiveCode Builder”