Skip to content

Instantly share code, notes, and snippets.

@coronarob
coronarob / main.lua
Last active August 29, 2015 14:21
Sample for copying a database to a writable location.
local sqlite3 = require( "sqlite3" )
local dbfunc = require("copyDBto")
local filename = "data.db"
local baseDir = system.DocumentsDirectory
-- Open "data.db". If the file doesn't exist, it will be created
local path = system.pathForFile( filename, baseDir )
local doesExist = io.open(path, "r")
@coronarob
coronarob / copyDBto.lua
Created May 18, 2015 03:02
Function to copy a database from your resource bundle to a writable area.
local M = {}
function M.copyDatabaseTo( filename, destination )
assert( type(filename) == "string", "string expected for the first parameter but got " .. type(filename) .. " instead." )
assert( type(destination) == "table", "table expected for the second paramter but bot " .. type(destination) .. " instead." )
local sourceDBpath = system.pathForFile( filename, system.ResourceDirectory )
-- io.open opens a file at path. returns nil if no file found
local readHandle, errorString = io.open( sourceDBpath, "rb" )
assert( readHandle, "Database at " .. filename .. " could not be read from system.ResourceDirectory" )
assert( type( destination.filename) == "string", "filename should be a string, its a " .. type( destination.filename ) )
print(type(destination.baseDir))
@coronarob
coronarob / countdowntimer.lua
Last active August 29, 2015 14:20
A sample countdown timer
display.setDefault("background", 0.2, 0.2, 0.4 )
-- Keep track of time in seconds
local secondsLeft = 20 * 60 -- 20 minutes * 60 seconds
local clockText = display.newText("20:00", display.contentCenterX, 80, native.systemFontBold, 80)
clockText:setFillColor( 0.7, 0.7, 1 )
local function updateTime()
-- decrement the number of seconds
@coronarob
coronarob / main.lua
Last active August 29, 2015 14:19
Android Social Sharing example
if "simulator" == system.getInfo( "environment" ) then
native.showAlert( "Build for device", "This plugin is not supported on the Corona Simulator, please build for an iOS device or Xcode simulator", { "OK" } )
end
-- Require the widget library
local widget = require( "widget" )
-- Use the iOS 7 theme for this sample
widget.setTheme( "widget_theme_android_holo_dark" )
@coronarob
coronarob / gist:8387deec14650adf03a4
Created April 6, 2015 01:02
Position objects on a grid
local GRID_WIDTH = 8
local GRID_HEIGHT = 8
local CELL_WIDTH = 40
local CELL_HEIGHT = 40
--
-- Create a 2D array to hold our objects.
local grid = {}
for i = 1, GRID_HEIGHT do
grid[i] = {}
end
@coronarob
coronarob / generateEvent_3.lua
Last active August 29, 2015 14:17
Generate the event from Lua
local requestRateApp =
{
name = "rateApp",
}
Runtime:dispatchEvent(requestRateApp)
@coronarob
coronarob / rateapp_2.cs
Created March 24, 2015 00:32
Enable the rateApp Event
private void OnCoronaRuntimeLoaded(
object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e)
{
// Keep a reference to the Corona runtime environment.
// It's needed so that your login window's results can be dispatched to Corona.
fCoronaRuntimeEnvironment = e.CoronaRuntimeEnvironment;
fCoronaRuntimeEnvironment.AddEventListener("rateApp", rateApp);
}
@coronarob
coronarob / rateApp.cs
Last active August 29, 2015 14:17
Windows Phone 8 function to rate an App. Add this near the bottom of your MainPage class.
/// <summary>Called by Lua when it is requesting a login popup to be shown.</summary>
/// <param name="sender">The CoronaRuntimeEnvironment that dispatched this event.</param>
/// <param name="e">Provides the Lua vent table's fields/properties.</param>
/// <returns>Returns a boxed object to Lua.</returns>
private CoronaLabs.Corona.WinRT.ICoronaBoxedData rateApp(
CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender,
CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e)
{
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();
@coronarob
coronarob / activity_button.lua
Last active August 29, 2015 14:17
Button to trigger the activity panel
widget = require( "widget" )
shareButton = widget.newButton({
label = "Share",
onRelease = showShare,
})
shareButton.x = display.contentCenterX
shareButton.y = display.contentCenterY
@coronarob
coronarob / activity_call.lua
Last active August 29, 2015 14:17
Function to show the activity popup.
local shareButton -- will define later
local function showShare()
local popupName = "activity"
local isAvailable = native.canShowPopup( popupName )
local isSimulator = "simulator" == system.getInfo( "environment" )
-- If it is possible to show the popup
if isAvailable then
local listener = {}