Giter Site home page Giter Site logo

develephant / corona-html5-plugin-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 16 KB

A bare-bones boilerplate to build Corona HTML5 plugins.

License: MIT License

Lua 41.03% JavaScript 11.93% Shell 47.04%
corona-sdk coronasdk corona plugin boilerplate template html5

corona-html5-plugin-boilerplate's Introduction

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('echo', 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.

corona-html5-plugin-boilerplate's People

Contributors

develephant avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

roaminggamer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.