/corona-html5-plugin-boilerplate

A bare-bones boilerplate to build Corona HTML5 plugins.

Primary LanguageShellMIT LicenseMIT

logo Corona HTML5 Plugin Boilerplate

A bare-bones boilerplate to build Corona HTML5 plugins.

Overview

  • Plugin files must reside in the root directory.
  • Plugin files are compiled with the HTML5 build.
  • JS file must be named <myplugin>_js.js to work.
  • Lua file must be named <myplugin>.lua to work.
  • Refs to myplugin inside files must be changed to your plugin name.
  • Refs to <myplugin>_js inside files must be changed to your plugin name.

Replace <myplugin> with your plugin name.

Direct Communication

JavaScript

Window property must be named <myplugin>_js. Replace <myplugin> with your plugin name.

window.myplugin_js = 
{
  echo: function(str) {
    return str
  }
};

Lua

Replace references to myplugin with your plugin name.

local myplugin = require("myplugin")

local result = myplugin.echo("Hello")

print(result) --> Hello

Event Driven

JavaScript (dispatcher)

Window property must be named <myplugin>_js. Replace <myplugin> with your plugin name.

window.myplugin_js = 
{
  echo: function(str) {
    this.dispatchEvent({name: 'echo', data: { value: str }})
  }
}

Lua (event listener)

Replace references to myplugin with your plugin name.

local myplugin = require("myplugin")

local function echoListener(event)
  print(event.data.value) --> Hello
end

myplugin.addEventListener(echoListener)

myplugin.echo("Hello")

Auto-Type Conversion

Lua to JS

  • Number
  • String
  • Boolean
  • Array (table) -> Array
  • Table -> Object

JS to Lua

  • Number
  • String
  • Boolean
  • Array -> Table (array)
  • Object -> Table

Notes

  • To see Lua print output you must run the index-debug.html of the HTML5 build (or use this).

create.sh

The create.sh tool will only work on Mac OS (Windows submission welcome 😉).

The tool creates a plugin directory and replaces all the myplugin file names and references with the specified plugin name.

⚠️ NOTE: Use this tool at your own risk.

Usage

Using the terminal, make sure you are in the root corona-html5-plugin-boilerplate directory and run:

./create.sh <plugin_name> <plugin_directory_path>

The directory should not exist, it will be created for you.

Example

./create.sh show_alert ~/Desktop/show_alert

Do not use dashes in your HTML5 plugin names.