One extension with multiple native library implementations
One extension with multiple native library implementations
Is it possible to have one extension with multiple functions that are implmented using native libararies from multiple platfroms?
-
- 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
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
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
Re: One extension with multiple native library implementations
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
Script Tracker https://github.com/bwmilby/scriptTracker
-
- Livecode Staff Member
- Posts: 192
- Joined: Thu Apr 18, 2013 2:48 pm
Re: One extension with multiple native library implementations
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).
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).
Re: One extension with multiple native library implementations
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.
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.