Skip to content

roaminggamer/corona-html5-cookie-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo Corona HTML5 Cookie Plugin

A basic plugin for setting, getting, and deleting cookies inside your Corona HTML5 apps.

Installation

  • Download the Corona HTML5 Cookie Plugin repository.

  • Move plugin/cookie.lua and plugin/cookie_js.js to the root of your HTML5 project.

  • Require the plugin in your code where you need it.

local cookie = require("cookie")

API

set

Set the cookie data.

cookie.set(name, value[, expiryDays])

Arguments

Name Description Type Required
name The name of the cookie. String Y
value The value of the cookie. String Y
expiryDays Days till expiration. Otherwise, lasts until deleted. Number N

Returns

The String 'set' on success.

Example

local result = cookie.set("username", "develephant", 1) -- expire in 1 day

print(result) --> set

get

Get the cookie data.

cookie.get(name)

Arguments

Name Description Type Required
name The name of the cookie. String Y

Returns

The cookie value as a String. If no cookie data exists, returns empty String.

Example

local username = cookie.get("username")

print(username) --> develephant

delete

Delete the cookie data.

cookie.delete(name)

Arguments

Name Description Type Required
name The name of the cookie. String Y

Returns

The String 'deleted' on success.

Example

local result = cookie.delete("username")

print(result) --> deleted

Demos

Corona

In the demo directory is the Corona project that you can compile yourself for testing. The demo does have some debug output that prints to the browser console. The plugin in the plugin directory does not output any debug info.

HTML5

In the html5 directory is a compiled version of the demo project that you can push up to your server for testing.

Notes

  • Only tested on Google Chrome at this time.

  • In the demos, the loading bar is not shown because of the black background. Hopefully this will be a build setting option in the future.

  • Reload the browser after setting a cookie to see that it has saved the cookie.

  • You can also view the cookie data using the Google Chrome Developer Tools window. Click the Application tab, and then Cookies (on the left side menu).


©2018 C. Byerley (develephant)

About

A Corona HTML5 Cookie Plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 68.4%
  • JavaScript 18.6%
  • Lua 13.0%