A CodeFlow blog

about live coding and more…

Fantastic Bindings!


A great new feature of CodeFlow 0.9.15 is the automatic creation of Project Bindings Libraries. But what role do Bindings Libs play in CodeFlow? And what make them so important?

Since the very beginning, the main goal of CodeFlow is to bring real interactivity to iOS Apps development. Real interactivity implies a development environment that provides the highest possible level of responsiveness between the writing of the application's source code and the execution of this code on the target device, while giving to the developer access to every capability of the iOS platform and the comfort of using iOS familiar APIs.

The use of Lua as the programming language for dynamic code in CodeFlow comes therefore with the possibility to have access in Lua to the whole iOS SDK. Except for a few low-level frameworks, almost every API, type, classe, protocol and method defined in the SDK can be used in Lua, in a very straightforward and natural way. This is one of CodeFlow's big strengths: be fully transparent regarding the set of APIs usable from the code, avoiding thus the constraints of a proprietary API, and the pitfall of a narrow target application domain.

Bindings du SDK IOS dans une application

On the technical side, enabling the Lua code to use SDK native APIs requires some sort of interface components, which are called Bindings Libraries. In CodeFlow a Binding Library is a package containing two kinds of contents: Lua API modules (i.e. Lua source files containing a Lua translation of SDK APIs), and code libraries that will be linked - when needed - with the target application in Xcode. The code in these libraries handles the necessary conversions between a Lua dynamic environment and iOS native system APIs.

Librairie de bindings

This could look a bit complex, but actually the the use of Bindings Libraries is fully transparent for the user. Once you have selected the SDK version that you want to use, CodeFlow takes care of everything: making code writing easier by proposing auto-completion for symbols in the SDK, configuring the Xcode project of the target application, so that it embeds the framework and bindings libraries needed by the Lua code... These things are automatically done, so you don't need to bother with bindings management.

Therefore Bindings Libraries are an essential component of a dynamic application development system like CodeFlow, because they act as a transparent communication path between the dynamic code and the rest of the system.

Accessing Application-Specific APIs

And for accessing application-specific APIs from Lua, how does that work?

In previous CodeFlow versions, prior to 0.9.15, it was definitely possible to reference (and to extend) specific compiled classes of the target application from the Lua code, to call their methods, or to use their properties and IBOutlets. In most cases that worked just well, but using such APIs was done somewhat in the blind, without completion support from the Lua editor in CodeFlow, and method calls were done in best-effort mode, relying on the (sometimes insufficient) information available in the Objective-C runtime. Besides, application-specific C types or functions were simply not accessible from Lua.

In a nutshell, before CodeFlow 0.9.15, integration between dynamic code and compiled code in an iOS application was a bit limited…

This is why I am happy to present the great new feature of CodeFlow 0.9.15: dynamic creation of Project Bindings Libraries, providing extended access from Lua to specific types and APIs of the target application.

Bindings projet dans une application

Project Bindings Libraries, this means that all APIs defined in your application's header files can now be used from your Lua code in CodeFlow, with the same level of transparency and quality that was previously only available for APIs of the system SDK. Naturally, Project Bindings Libraries can also include the APIs of third-party libraries and CocoaPods used in your application project! 😃

Specifically, Project Bindings Libraries give access to the vast majority of symbols defined in .h files belonging to your Xcode project; this includes entities declared as #define, enum, struct, C function, const global variable (e.g. string constants declared as extern NSString* const), and, of course, Objective-C classes and protocols, with their methods and properties.

Each CodeFlow project has its own Project Bindings Library. This Bindings Library is automatically created and updated, so as to stay in-sync with the target application's Xcode project. You can configure the content of a Project Bindings Library through a dedicated interface in CodeFlow (read below).

Using Project Bindings

In CodeFlow 0.9.15, if a given CodeFlow project has an associated Xcode project, then a Project Bindings Library is automatically created, to provide Lua interfaces for the C and Objective-C APIs defined in this Xcode project. By default the Project Bindings Library includes APIs defined in all .h files of the Xcode project, but the list of visible header files can be modified in the corresponding Bindings Editor.

As an example, let's consider a WatchKit test application named WatchApp1, that show the following structure under Xcode:

Structure du projet Xcode

If we select the Project Bindings Library in the associated CodeFlow project, we can see the Bindings Editor for it. The Bindings Editor presents a file tree that mirrors the Xcode project structure and that contains every .h file in this project.

Éditeur de bindings projet

Each .h file (and each group) can be individually selected or unselected, and only APIs declared in selected header files will be included in the Project Bindings Library. In this example, we are only interested in APIs in the "WatchKit Extension" group; so we have unchecked the "WatchApp1" group in the list.

In addition to the selection checkbox, the Bindings Editor displays for every header file in the project:

  • a QuickLook button that shows a preview of the .h header file;
  • a Bindings-generation-result indicator for this file: green in case of success, yellow if warnings were emitted during the generation, red if the generation did fail, or gray if the generation did not take place; a click on this indicator displays detailed information about the status;
  • a direct access button to the generated Lua module API.

Project Bindings Libraries are automatically updated if one of the selected .h files is modified, or if the contents of the associated Xcode Project is changed (e.g. if you add a new .h file in the project). Conversely when you change the list of selected header files in the Bindings Editor, you have to explicitly tell CodeFlow to update the Bindings Library, by either clicking on the Refresh button in the Bindings Editor or by selecting the Update Lua Bindings… command in the Program menu.

And, well… that's about all you need to know for using this new Project Bindings feature in CodeFlow.

The actual usage of the Project Bindings Library in your code is transparently managed by CodeFlow, just as with SDK Bindings Libraries. Project APIs are added to code-completion proposals; Project Bindings code libraries are automatically added to the associated Xcode project if needed; and, during the target app execution, project-specific data are created with the expected types, project methods and function are called with the specified parameter types…

All this is made possible by Bindings Libraries. In CodeFlow they are an essential component of the live-coding system, almost invisible but so important. And with CodeFlow 0.9.15 and Project Bindings Libraries, live coding on iOS takes a major feature boost. And really, for the developer, It just works!

Post a Comment


Recent posts

Blog Post
Aug 1, 2016

CodeFlow 1.0.2

CodeFlow 1.0.2 is a minor release that focuses on improving the Live Application Developer's Experience.

Aug 1, 2016
Blog Post
Jun 16, 2016

CodeFlow 1.0.1 and WWDC 2016

The just-released CodeFlow 1.0.1 brings support for the new iOS 10, tvOS 10 and macOS 10.12 announced at WWDC 2016 this week.

Jun 16, 2016
Blog Post
Jun 9, 2016

CodeFlow turns 1.0

It has been some time since the last beta of CodeFlow, version 0.9.20 was released in January this year. And all this time, we have worked very hard to improve CodeFlow, and to turn it into an effective Application Development System that we love to…

Jun 9, 2016

Last tweets

Jun 8, 2018
@JLJumpertz
✅ Wow, @celedev CodeFlow looks really good in dark mode on macOS 10.14 Mojave! 😃
Still a work in progress, but it took me only a few hours to reach this point, while keeping it compatible with macOS 10.11+ 😎
CodeFlow = live-code native iOS apps in Lua celedev.com
Jun 8, 2018
May 17, 2018
@JLJumpertz
🎉🥂Time-Flow, an iOS app created with @celedev CodeFlow by @alf147 is on the AppStore!
The approval process took less than 24 hours. 😎
#LuaLang #livecoding #iOS
itunes.apple.com/us/app/time-fl…
May 17, 2018
Apr 2, 2018
Minor CodeFlow update today: v1.2.3 fixes an issue with Xcode 9.3. Check for update or download it directly from celedev.com/en/download/
Apr 2, 2018
Feb 12, 2018
New CodeFlow version 1.2.2 today: it solves an error that could occur when calling certain kinds of Swift closures or ObjC blocks from Lua.
Thanks @alf147 for reporting the issue! 😀
Check for update in CodeFlow, or download version 1.2.2 from celedev.com/en/download/.
Feb 12, 2018
Feb 8, 2018
The LuaPanda 🐼sample application has also been updated for CodeFlow 1.2.1.
To get it from GitHub: github.com/celedev/LuaPan…
Feb 8, 2018
Feb 8, 2018
CodeFlow 1.2.1 is now available for upgrade. This is a bugfix release recommended to all users. 😎
Check for update in the appplication,
or download it from celedev.com/en/download/,
or simply read about the changes here: celedev.com/en/download/co…
Feb 8, 2018
Feb 2, 2018
@JLJumpertz
Live iOS app development strikes back!
Version 1.2 of CodeFlow is out, with lots of improved features, for a unique interactive native app development experience. 😀
- download celedev.com/en/download/
- changelog celedev.com/en/download/co…
(by @celedev)
Feb 2, 2018
Dec 7, 2017
🛠New CodeFlow SDK Bindings are available for all supported Xcode versions: 9.2, 8.3, and 7.3. 😊
celedev.com/en/download/
Dec 7, 2017
Aug 9, 2017
🛠CodeFlow SDK Bindings for Xcode 9 beta 5 are available for download. Enjoy! 😊
celedev.com/en/download/
Aug 9, 2017
Jul 11, 2017
New APIs in Xcode 9 / iOS 11 beta 3? CodeFlow supports them from day 1. 😀
🛠 Download updated OS SDK bindings from celedev.com/en/download/
Jul 11, 2017
Jul 2, 2017
CodeFlow 1.1.1 is out, and supports real-time native app development for iOS 11 and macOS 10.13.
Check for update or celedev.com/en/download/
Jul 2, 2017
Dec 5, 2016
@JLJumpertz
"Programming iOS in Lua - A bridge story"
Slides of my talk at Lua Workshop 2016 are here: slideshare.net/jljumpertz/pro…
#lualang #iosdev
Dec 5, 2016
Oct 11, 2016
Little Lua red Panda is now on GitHub! github.com/celedev/LuaPan…
A SceneKit 3D game in #LuaLang with dynamic update of all 3D assets and code
Oct 11, 2016
Oct 3, 2016
CodeFlow 1.0.3 is out!
⚡️ Live SceneKit assets, Sierra support, and more…
celedev.com/en/download/#c…
#lualang #iosdev
Oct 3, 2016
Oct 1, 2016
@aligatr
@Javi @nicklockwood same and also sad they didn't mention Redux realm.io/news/benji-enc… nor @celedev for Live Reloading & Faster iterations
Oct 1, 2016