This guide explains how a Corona Enterprise for iOS project fits together.
The following elements apply to a Corona Enterprise project:
ios/App.xcodeproj
— This is the main project for building and running your app within Xcode. We recommend that you use this project template as the starting point for your Xcode project since it contains custom build phases that take care of packaging your Lua sources and resource files ios/AppCoronaDelegate.h
/AppCoronaDelegate.mm
— The main application entry points go here. The class conforms to the CoronaDelegate protocol, so you will get notified immediately before and after main.lua
is loaded and executed. You can also add UIApplicationDelegate
methods. We recommend that you add new Lua libraries via plugins.Corona/
— A normal Corona project consists of your Lua files such as main.lua
, along with additional resource files like images, audio, video, etc. By default, ios/App.xcodeproj
is set up to assume that these files reside inside a folder called Corona
that sits alongside the ios
folder.For plugins, there are additional files and directories of interest:
ios/Plugin.xcodeproj
— This is the main project that contains the Lua library that you are exposing to your application. This is a dependency of App.xcodeproj
, so it will get built automatically. You only need to open this project if you want to build the plugin separately.ios/Plugin/
— This is where the implementation of plugin.library
goes.ios/Plugin/PluginLibrary.h
/Plugin/PluginLibrary.mm
— This implements the plugin.library
.This brief walkthrough outlines the flow of the CoronaEnterprise/ProjectTemplates/App/
project for iOS:
ios/main.mm
At launch time, MyCoronaDelegate
is registered as the class implementing the CoronaDelegate interface. Corona will instantiate an instance of this class and assume the designated initializer is init
.
ios/AppCoronaDelegate.mm
Right before main.lua
is invoked, the willLoadMain:
method is invoked. At this point, OpenGL is set up and all Corona frameworks are available.
Corona/main.lua
In the Lua code, plugin.library
is loaded via require()
. The Corona engine will then look for a corresponding C function called luaopen_plugin_library
and invoke it. The name of this function is dynamic and is constructed using the original library name passed to require()
. It takes that name and adds a prefix luaopen_
to it, then replaces .
with _
.
ios/Plugin/PluginLibrary.mm
When luaopen_plugin_library
is invoked, it calls PluginLibrary::Open
which does all of the heavy lifting, for example creating the Lua library table, registering the Lua methods like show()
, and then leaving the table at the top of the Lua stack.