One extension with multiple native library implementations

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
bmont
Posts: 13
Joined: Thu Jun 15, 2006 3:04 pm

One extension with multiple native library implementations

Post by bmont » Mon Aug 06, 2018 7:59 pm

Is it possible to have one extension with multiple functions that are implmented using native libararies from multiple platfroms?

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: One extension with multiple native library implementations

Post by trevordevore » Mon Aug 06, 2018 8:19 pm

While I haven't tested it, I would think so. LiveCode doesn't try to resolve external code libraries until you actually call the function. You could probably do something like this:

Code: Select all

# Define private foreign handlers that access native libraries on Windows OS
...

# Define private foreign handlers that access native libraries on macOS
...

public handler doSomething returns String
  if the operating system is "mac" then
    # Call Mac native library handler defined above
  else if the operating system is "windows" then
    # Call Windows native library handler defined above
  else if ...

  end if
end handler
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: One extension with multiple native library implementations

Post by bwmilby » Mon Aug 06, 2018 10:28 pm

There is an example on GitHub where they have one widget include native controls for several platforms. That one is done with sub-modules, but I would agree that it should be possible.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: One extension with multiple native library implementations

Post by livecodeali » Mon Aug 13, 2018 9:33 am

Yes, the cross platform button example is how we would recommend structuring such an extension:
https://github.com/livecode/livecode/pull/6266

However it does potentially over-complicate things it if the extension is very simple, and you can do as Trevor suggests (in fact the first LiveCode widget to do such a thing was the map widget - it was implemented exactly this way with all the code in one module).

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

Re: One extension with multiple native library implementations

Post by LCMark » Mon Aug 13, 2018 10:50 am

Just to expand on what Ali and Trevor mentioned about this...

The LCB runtime does not bind to a foreign handler until it is used - so you can have all bindings for all platforms in one module.

Even if we change this at some point (for efficiency reasons) it would still work the same way from the point of view of running code.

i.e. Only things that do bind on the current platform will bind. Any error from binding ahead of time (e.g. from trying to bind to an obj-c handler on Windows) will just throw the appropriate error on first use.

Post Reply

Return to “LiveCode Builder”