Corona Enterprise — iOS Project Structure

This guide explains how a Corona Enterprise for iOS project fits together.

Files/Directories

The following elements apply to a Corona Enterprise project:

Corona Project Files

  • 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.

Plugins

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.

Walkthrough

This brief walkthrough outlines the flow of the CoronaEnterprise/ProjectTemplates/App/ project for iOS:

  1. 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.

  2. 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.

  3. 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 _.

  4. 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.