### Start Recording Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/Recording/startRecording.markdown This example shows how to create a new recording object and start recording audio. ```lua local filePath = system.pathForFile( "newRecording.aif", system.DocumentsDirectory ) local r = media.newRecording( filePath ) r:startRecording() ``` -------------------------------- ### Example usage of media.newRecording() Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/media/newRecording.markdown This example demonstrates how to create a new recording object, specify a file path, and start recording. ```lua local filePath = system.pathForFile( "newRecording.aif", system.DocumentsDirectory ) r = media.newRecording( filePath ) r:startRecording() ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/startapp/show.markdown Shows how to initialize the StartApp plugin, load an interstitial ad, and display various ad types. ```lua local startapp = require( "plugin.startapp" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) -- Load an StartApp ad startapp.load( "interstitial" ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded print( event.type ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) elseif ( event.phase == "displayed" ) then -- The ad was displayed/played print( event.type ) elseif ( event.phase == "hidden" ) then -- The ad was closed/hidden print( event.type ) elseif ( event.phase == "clicked" ) then -- The ad was clicked/tapped print( event.type ) elseif ( event.phase == "reward" ) then -- Rewarded video ad playback completed print( event.type ) end end -- Initialize the StartApp plugin startapp.init( adListener, { appId="Your App ID" } ) -- Show banner ad. no need to pre-load banner startapp.show( "banner" , { adTag = "menu top banner", yAlign = "top", bannerType = "standard" } ) -- Sometime later, show an interstitial ad if ( startapp.isLoaded( "interstitial" ) ) then startapp.show( "interstitial" ) end ``` -------------------------------- ### Get Selection Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/TextBox/getSelection.markdown This example demonstrates how to get the start and end positions of the text selection in a TextBox. It shows the return values for different cursor positions. ```lua local textBox = native.newTextBox( 160, 240, 280, 40 ) textBox.text = "asdf" native.setKeyboardFocus( textBox ) local start, finish = textBox:getSelection() -- if native cursor is placed after the "f" in the text, start and finish would return 4, 4 -- if native cursor is selecting the whole text, start and finish would return, 0, 4 ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/revmob/show.markdown Shows how to initialize RevMob, load an ad, and then display it. ```lua local revmob = require( "plugin.revmob" ) local placementID = "PLACEMENT_ID" local function adListener( event ) if ( event.phase == "sessionStarted" ) then -- Successful initialization -- Load a RevMob ad revmob.load( "banner", placementID ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded -- Show the ad revmob.show( placementID, { yAlign="top" } ) end end -- Initialize RevMob revmob.init( adListener, { appId="YOUR_APP_ID" } ) ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/appnext/getButtonText.markdown Gets the install button's text. ```lua local appnext = require( "plugin.appnext" ) local function adListener( event ) print( "Received " .. event.event .. " for " .. event.adKey .. " with message: " .. event.message ) end -- Initialize the Appnext plugin appnext.init( adListener ) -- Create your ads local interstitialPlacementID local platform = system.getInfo( "platformName" ) if ( platform == "iPhone OS" ) then interstitialPlacementID = "YOUR_IOS_INTERSTITIAL_PLACEMENT_ID" elseif ( platform == "Android" ) then interstitialPlacementID = "YOUR_ANDROID_INTERSTITIAL_PLACEMENT_ID" end local interstitialAdKey = appnext.createAd( "interstitial", interstitialPlacementID ) appnext.setButtonText( interstitialAdKey, "Install App" ) print( "Button text: " .. appnext.getButtonText( interstitialAdKey ) ) ``` -------------------------------- ### Get touch event time Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/event/touch/time.markdown This example demonstrates how to get the time in milliseconds since the start of the application within a touch event listener function. ```lua local object = display.newImage( "ball.png" ) function object:touch( event ) if event.phase == "began" then print(event.time/1000 .. " seconds since app started." ) end return true end object:addEventListener( "touch", object ) ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/licensing/index.markdown This example demonstrates how to initialize the licensing library and verify the app's license. ```lua local licensing = require( "licensing" ) local function licensingListener( event ) if not ( event.isVerified ) then -- Failed to verify app from the Google Play store; print a message print( "Pirates!!!" ) end end local licensingInit = licensing.init( "google" ) if ( licensingInit == true ) then licensing.verify( licensingListener ) end ``` -------------------------------- ### Get Last Modified Time Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/guide/data/LFS/index.markdown Example of how to retrieve the last modification time of a file using the lfs.attributes function. ```lua local lfs = require( "lfs" ) local filePath = system.pathForFile( "mydata.txt", system.DocumentsDirectory ) -- Get/print last modified time local fileAttributes = lfs.attributes( filePath ) print( "File last modified: " .. fileAttributes.modification ) ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/supersonic/show.markdown Shows how to initialize the Supersonic plugin, load an offer wall ad, and then display it. ```lua local supersonic = require( "plugin.supersonic" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Load an offer wall ad supersonic.load( "offerWall", "user2353" ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded -- Show the ad supersonic.show( event.type ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end -- Initialize the Supersonic plugin supersonic.init( adListener, { appKey="YOUR_APP_KEY" } ) ``` -------------------------------- ### Get Turn Status Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/gpgs/multiplayer/type/Match/getTurnStatus.markdown Example of how to get the turn status of a match. ```lua local turnStatus = object.getTurnStatus() print(turnStatus) ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/applovin/show.markdown Shows how to initialize the AppLovin plugin, load an ad, and then show it if it is loaded. ```lua local applovin = require( "plugin.applovin" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.isError ) -- Load an AppLovin ad applovin.load( "interstitial" ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded print( event.type ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) elseif ( event.phase == "displayed" or event.phase == "playbackBegan" ) then -- The ad was displayed/played print( event.type ) elseif ( event.phase == "hidden" or event.phase == "playbackEnded" ) then -- The ad was closed/hidden print( event.type ) elseif ( event.phase == "clicked" ) then -- The ad was clicked/tapped print( event.type ) end end -- Initialize the AppLovin plugin applovin.init( adListener, { sdkKey="YOUR_SDK_KEY" } ) -- Sometime later, show the ad local isAdLoaded = applovin.isLoaded( "interstitial" ) if ( isAdLoaded == true ) then applovin.show( "interstitial" ) end ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/mediaBrix/show.markdown Shows how to initialize MediaBrix, load an ad, and then display it. ```lua local mediaBrix = require( "plugin.mediaBrix" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.isError ) -- Load a MediaBrix ad mediaBrix.load( "PLACEMENT_ID" ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded print( event.type ) -- Show the ad mediaBrix.show( "PLACEMENT_ID" ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) elseif ( event.phase == "displayed" ) then -- The ad was displayed print( event.type ) elseif ( event.phase == "closed" ) then -- The ad was closed print( event.type ) end end -- Initialize MediaBrix mediaBrix.init( adListener, { appId="YOUR_APP_ID" } ) ``` -------------------------------- ### Get Percentile Ranks Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/gamecircle/Leaderboard/PercentileItem.markdown Example of how to get percentile ranks for a leaderboard. ```lua local leaderboardId = "myFirstLeaderboard" local gamecircle = require("plugin.gamecircle") gamecircle.Init(false, true, false) function LeaderboardCallback(returnValue) if returnValue.isError == true then print("Get Percentile request returned with error message: " .. returnValue.errorMessage) else print("Percentile information returned for leaderboard " .. returnValue.leaderboard.name) print("The local user's index in the list is : " .. returnValue.userIndex) print("-( -1 means user is not on leaderboard)") print("Here is the statistical information:") for i,stat in ipairs(returnValue) do print("#" .. i .. " " .. stat.playerAlias .. "-" .. stat.playerScore .. "-" .. percentile) end end end gamecircle.Leaderboard.GetPercentileRanks(leaderboardId, "GLOBAL_WEEK", LeaderboardCallback) ``` -------------------------------- ### Get Linear Velocity From Local Point Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/Body/getLinearVelocityFromLocalPoint.markdown This example demonstrates how to get the world-space linear velocity of a specific point on a physics body using its local coordinates. ```lua local myRect = display.newRect( 200, 200, 80, 40 ) physics.addBody( myRect, "dynamic", { density = 1.0 } ) -- Give it linear motion and a spin myRect:setLinearVelocity( 50, 0 ) -- moving right myRect.angularVelocity = 90 -- rotating -- Pick a local point offset from the center (e.g., right side) local localX, localY = 40, 0 -- Get the velocity of that local point in world space local vx, vy = myRect:getLinearVelocityFromLocalPoint( localX, localY ) if vx and vy then print( "Velocity at local (" .. localX .. ", " .. localY .. "): " .. vx .. ", " .. vy ) end ``` -------------------------------- ### Sample Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/vk-direct/index.markdown Example of initializing the VK Direct plugin. ```lua local loadingText = display.newText( "Loading...", display.contentCenterX, display.contentCenterY, nil, 20) local vk = require("plugin_vk_direct") local function vkListener( event ) if event.method == "init" then if event.status == "success" then composer.gotoScene( "menu" ) loadingText:removeSelf( ) else loadingText.text = "VK Initialization error" end end end vk.init(vkListener) ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/appodeal/show.markdown Shows how to initialize the Appodeal plugin and display a banner ad. ```lua local appodeal = require( "plugin.appodeal" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "banner", { yAlign="top" } ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end -- Initialize the Appodeal plugin appodeal.init( adListener, { appKey="YOUR_APP_KEY" } ) ``` -------------------------------- ### Get Slider Value Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/SliderWidget/value.markdown This example shows how to get the current value of a SliderWidget. ```lua local sliderPercentage = mySlider.value ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/chartboost/show.markdown Shows how to initialize the Chartboost plugin and display an interstitial ad. ```lua local chartboost = require( "plugin.chartboost" ) -- Chartboost listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization chartboost.load( "interstitial" ) elseif ( event.phase == "loaded" ) then if ( event.type == "interstitial" ) then chartboost.show( "interstitial" ) end end end -- Initialize the Chartboost plugin chartboost.init( adListener, { appId="YOUR_CHARTBOOST_APP_ID", appSig="YOUR_CHARTBOOST_APP_SIGNATURE" } ) ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/ProgressViewWidget/getProgress.markdown This example shows how to get the current progress value of a ProgressViewWidget. ```lua local currentProgress = progressView:getProgress() ``` -------------------------------- ### math.fmod() example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/math/fmod.markdown Example showing how to use math.fmod() to get the remainder of a division. ```lua print(math.fmod(5.3, 2)) ---> 1.3 print(math.fmod(1, 0)) ---> NaN ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/unityads/show.markdown Shows how to initialize the Unity Ads plugin and then display an ad. ```lua local unityads = require( "plugin.unityads" ) -- Unity Ads listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) end end -- Initialize the Unity Ads plugin unityads.init( adListener, { gameId="YOUR_UNITYADS_GAME_ID" } ) -- Sometime later, show an ad if ( unityads.isLoaded( "YOUR_UNITYADS_PLACEMENT_ID" ) ) then unityads.show( "YOUR_UNITYADS_PLACEMENT_ID" ) end ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/superawesome/show.markdown Shows how to initialize the SuperAwesome plugin, load a banner ad, and then display it. ```lua local superawesome = require( "plugin.superawesome" ) -- Pre-declare a placement ID local myPlacementID = "YOUR_PLACEMENT_ID" local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Load a banner ad superawesome.load( "banner", { placementId=myPlacementID } ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded print( event.type ) print( event.placementId ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.placementId ) print( event.isError ) end end -- Initialize the SuperAwesome plugin superawesome.init( adListener, { testMode=true } ) -- Sometime later, show the ad if ( superawesome.isLoaded( myPlacementID ) ) then superawesome.show( myPlacementID, { y="bottom" } ) end ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/audio/reservedChannels.markdown This example demonstrates how to get the number of reserved audio channels. ```lua local result = audio.reservedChannels print( result ) ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/kidoz/show.markdown Demonstrates how to initialize the KIDOZ plugin, load a panel view ad, and then show it. ```lua local kidoz = require( "plugin.kidoz" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) -- Load a KIDOZ panel view ad kidoz.load( "panelView", { adPosition="bottom" } ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded print( event.type ) -- Show the ad kidoz.show( "panelView" ) end end -- Initialize the KIDOZ plugin kidoz.init( adListener, { publisherID="YOUR_PUBLISHER_ID", securityToken="YOUR_SECURITY_TOKEN" } ) ``` -------------------------------- ### Get Auth Session Ticket Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/steamworks/getAuthSessionTicket.markdown Example of how to get the authentication token and listen for the response. ```lua local steamworks = require( "plugin.steamworks" ) local ticketToken local function onAuthTicketResponse(event) if event.isError then print("Error had occurred, code " .. event.resultCode) return end -- use the value of the ticketToken here end steamworks.addEventListener( "authSessionTicketResponse", onAuthTicketResponse ) ticketToken = steamworks.getAuthSessionTicket() ``` -------------------------------- ### gpn.init() Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/plugin.gpn/init.markdown Example demonstrating how to initialize the gpn plugin with a listener function and initialization properties. ```lua -- gpn listener function local function listener( event ) if event.type == "received" then -- Interstitial ad is received: it’s safe to present it now. elseif event.type == "failed" then -- Interstitial ad is failed to receive. local code = event.error_code local message = event.error_message -- You should restart your interstitial request elseif event.type == "opened" then -- Interstitial ad presented full screen modal view. You can pause your game here. elseif event.type == "closed" then -- Interstitial ad hided full screen modal view. You can resume your game here. elseif event.type == "killedLowMem" then -- iOS only: Interstitial ad was destroyed after receiving low memory warning. -- You should restart your interstitial request end end local init_properties = { iosAppId = "your_ios_app_id_here", androidAppId = "your_android_app_id_here", -- debugMode = true, -- iosKillsOnLowMemory = false } gpn.init( listener, init_properties ) ``` -------------------------------- ### Get Preferred Orientation Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/appnext/getPreferredOrientation.markdown This example demonstrates how to set and then get the preferred orientation for an ad. ```lua local appnext = require( "plugin.appnext" ) local function adListener( event ) print( "Received " .. event.event .. " for " .. event.adKey .. " with message: " .. event.message ) end -- Initialize the Appnext plugin appnext.init( adListener ) -- Create your ads local fullscreenPlacementID local platform = system.getInfo( "platformName" ) if ( platform == "iPhone OS" ) then fullscreenPlacementID = "YOUR_IOS_FULLSCREEN_PLACEMENT_ID" elseif ( platform == "Android" ) then fullscreenPlacementID = "YOUR_ANDROID_FULLSCREEN_PLACEMENT_ID" end local fullscreenAdKey = appnext.createAd( "fullscreen", fullscreenPlacementID ) appnext.setPreferredOrientation( fullscreenAdKey, "landscape" ) print( "Preferred Orientation: " .. appnext.getPreferredOrientation( fullscreenAdKey ) ) ``` -------------------------------- ### Get the number of particles Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/ParticleSystem/particleCount.markdown This example shows how to get the number of particles alive in a ParticleSystem. ```lua local particleSystem = physics.newParticleSystem( { filename = "particle.png", radius = 2 } ) print( particleSystem.particleCount ) ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/event/video/index.markdown This example demonstrates how to create a video object, load a video file, add an event listener, and play the video. ```lua local video = native.newVideo( display.contentCenterX, display.contentCenterY, 320, 480 ) local function videoListener( event ) print( "Event phase: " .. event.phase ) end -- Load a video video:load( "myVideo.m4v", system.DocumentsDirectory ) -- Add video event listener video:addEventListener( "video", videoListener ) -- Play video video:play() ``` -------------------------------- ### Get Content Bounds Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/DisplayObject/contentBounds.markdown This example demonstrates how to get the content bounds of a display object. ```lua local rect = display.newRect( 100, 100, 50, 50 ) rect:setFillColor( 1, 0, 0 ) local bounds = rect.contentBounds print( "xMin: ".. bounds.xMin ) -- xMin: 75 print( "yMin: ".. bounds.yMin ) -- yMin: 75 print( "xMax: ".. bounds.xMax ) -- xMax: 125 print( "yMax: ".. bounds.yMax ) -- yMax: 125 ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/system/ApplicationSupportDirectory.markdown Get path for file "data.txt" in the application support directory and then open, read, or create the file. ```lua -- Get path for file "data.txt" in the application support directory local path = system.pathForFile( "data.txt", system.ApplicationSupportDirectory ) -- Open the file from the path local fh, reason = io.open( path, "r" ) if fh then -- File exists; read its contents into a string local contents = fh:read( "*a" ) print( "Contents of " .. path .. "\n" .. contents ) else -- File open failed; output the reason print( "File open failed: " .. reason ) -- Create file since it doesn't exist yet fh = io.open( path, "w" ) if fh then print( "Created file" ) else print( "Create file failed!" ) end local numbers = { 1,2,3,4,5,6,7,8,9 } fh:write( "Feed me data!\n", numbers[1], numbers[2], "\n" ) for _,v in ipairs( numbers ) do fh:write( v, " " ) end fh:write( "\nNo more data\n" ) end io.close( fh ) ``` -------------------------------- ### Get Volume Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/iTunes/getVolume.markdown This example demonstrates how to retrieve the current playback volume after setting it. ```lua local iTunes = require( "plugin.iTunes" ) -- Table to store media items local mediaItems = {} -- Function that is executed when song playback is complete local function onPlaybackEnded() print( "Playback completed!" ) end -- Function that is executed after media item(s) have been chosen local function onMediaChosen( event ) if ( event.data ) then for i=1,#event.data do mediaItems[i] = event.data[i] end --play the first item chosen iTunes.play( mediaItems[1].url, onPlaybackEnded ) --set the playback volume iTunes.setVolume( 0.5 ) --print the playback volume iTunes.getVolume() end end local iTunesOptions = { allowsPickingMultipleItems = true, promptTitle = "Select some songs" } iTunes.show( iTunesOptions, onMediaChosen ) ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/adcolony/show.markdown Shows how to initialize the AdColony plugin and then display an ad. ```lua local adcolony = require( "plugin.adcolony" ) -- AdColony listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) end end -- Initialize the AdColony plugin adcolony.init( adListener, { appId = "YOUR_ADCOLONY_APP_ID", adZones = { interstitial = "YOUR_ADCOLONY_ZONE_ID_1", rewardedVideo = "YOUR_ADCOLONY_ZONE_ID_2" } }) -- Sometime later, show an ad if ( adcolony.isLoaded( "interstitial" ) ) then adcolony.show( "interstitial" ) end ``` -------------------------------- ### Basic ZeroConf Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/zeroconf/index.markdown This example demonstrates how to publish a service and then discover other services of the same type. It includes a listener function to handle service discovery events (found and lost). ```lua -- Publishes a service of type '_corona_test._tcp' and then starts discovery for the service -- Require the plugin local zeroconf = require( "plugin.zeroconf" ) -- Listener to be called for ZeroConf events local function zeroconfListener( event ) -- Service has been found if ( event.phase == "found" and not event.isError ) then print( "SERVICE FOUND" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end if event.port then print( "Port: " .. tostring(event.port) ) end if ( event.addresses and #event.addresses > 0 ) then print( "Service provider addresses:" ) for i = 1,#event.addresses do print( " " .. event.addresses[i] ) end end -- Service has been lost! elseif event.phase == "lost" then print( "SERVICE LOST!" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end end end -- Initialize listener zeroconf.init( zeroconfListener ) -- Generate a service name local serviceName = system.getInfo("name") .. " (" .. system.getInfo("platformName") .. ")" -- Publish a service (make it discoverable over the network) local service = zeroconf.publish( { port=2929, name=serviceName, type="_corona_test._tcp" } ) -- Start looking for published services local browser = zeroconf.browse( { type="_corona_test._tcp" } ) ``` -------------------------------- ### Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/appnext/getCategories.markdown This example demonstrates how to set and get ad categories using the Appnext plugin. ```lua local appnext = require( "plugin.appnext" ) local function adListener( event ) print( "Received " .. event.event .. " for " .. event.adKey .. " with message: " .. event.message ) end -- Initialize the Appnext plugin appnext.init( adListener ) -- Create your ads local interstitialPlacementID local platform = system.getInfo( "platformName" ) if ( platform == "iPhone OS" ) then interstitialPlacementID = "YOUR_IOS_INTERSTITIAL_PLACEMENT_ID" elseif ( platform == "Android" ) then interstitialPlacementID = "YOUR_ANDROID_INTERSTITIAL_PLACEMENT_ID" end local interstitialAdKey = appnext.createAd( "interstitial", interstitialPlacementID ) appnext.setCategories( interstitialAdKey, "Action, Adventure" ) print( "Categories set: " .. appnext.getCategories( interstitialAdKey ) ) ``` -------------------------------- ### getLocalAxisA() Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/Joint/getLocalAxisA.markdown This example demonstrates how to get the local axis A coordinates for a joint. ```lua local lax, lay = myJoint:getLocalAxisA() ``` -------------------------------- ### Initialize the StartApp plugin Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/startapp/init.markdown This example shows how to initialize the StartApp plugin with a listener function and initialization parameters, including the app ID and whether to enable return ads. ```lua local startapp = require( "plugin.startapp" ) -- StartApp listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) end end -- Initialize the StartApp plugin startapp.init( adListener, { appId="Your App ID", enableReturnAds = true } ) ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/audio/unreservedUsedChannels.markdown This example demonstrates how to get the number of unreserved used audio channels. ```lua local result = audio.unreservedUsedChannels print( result ) ``` -------------------------------- ### Syntax Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/licensing/init.markdown Initializes the licensing service library by specifying the name of the licensing provider. ```lua licensing.init( providerName ) ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/audio/usedChannels.markdown This example demonstrates how to get the number of audio channels currently in use. ```lua local result = audio.usedChannels print( result ) ``` -------------------------------- ### gameNetwork.init() Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/gameNetwork-apple/init.markdown This example demonstrates how to initialize the Game Center API and handle the callback for login status. ```lua local gameNetwork = require( "gameNetwork" ) local loggedIntoGC = false local function initCallback( event ) if ( event.type == "showSignIn" ) then -- This is an opportunity to pause your game or do other things you might need to do while the Game Center Sign-In controller is up. elseif ( event.data ) then loggedIntoGC = true native.showAlert( "Success!", "", { "OK" } ) end end local function onSystemEvent( event ) if ( event.type == "applicationStart" ) then gameNetwork.init( "gamecenter", initCallback ) return true end end Runtime:addEventListener( "system", onSystemEvent ) ``` -------------------------------- ### Basic Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/applovin/load.markdown This example demonstrates how to initialize the AppLovin plugin and load an interstitial ad. ```lua local applovin = require( "plugin.applovin" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.isError ) -- Load an AppLovin ad applovin.load( "interstitial" ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded print( event.type ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end -- Initialize the AppLovin plugin applovin.init( adListener, { sdkKey="YOUR_SDK_KEY" } ) ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/audio/unreservedFreeChannels.markdown This example demonstrates how to get the number of unreserved free audio channels. ```lua local result = audio.unreservedFreeChannels print( result ) ``` -------------------------------- ### Start Requesting Interstitials Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/plugin.gpn/startRequestingInterstitials.markdown Example of how to start requesting interstitial ads after initializing the gpn instance. ```lua gpn.startRequestingInterstitials() ``` -------------------------------- ### Show Ad Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/appnext/showAd.markdown This example demonstrates how to initialize the Appnext plugin, create and load ads, and then show a full-screen video ad. ```lua local appnext = require( "plugin.appnext" ) local function adListener( event ) print( "Received " .. event.event .. " for " .. event.adKey .. " with message: " .. event.message ) end -- Initialize the Appnext plugin appnext.init( adListener ) -- Create your ads local fullscreenPlacementID local rewardedPlacementID local platform = system.getInfo( "platformName" ) if ( platform == "iPhone OS" ) then fullscreenPlacementID = "YOUR_IOS_FULLSCREEN_PLACEMENT_ID" rewardedPlacementID = "YOUR_IOS_REWARDED_PLACEMENT_ID" elseif ( platform == "Android" ) then fullscreenPlacementID = "YOUR_ANDROID_FULLSCREEN_PLACEMENT_ID" rewardedPlacementID = "YOUR_ANDROID_REWARDED_PLACEMENT_ID" end local fullscreenAdKey = appnext.createAd( "fullscreen", fullscreenPlacementID ) local rewardedAdKey = appnext.createAd( "rewarded", rewardedPlacementID ) -- Load your ads before showing appnext.loadAd( fullscreenAdKey ) appnext.loadAd( rewardedAdKey ) -- Show full-screen video ad if ( appnext.adIsLoaded( fullscreenAdKey ) ) then appnext.showAd( fullscreenAdKey ) end ``` -------------------------------- ### Get deep link Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/tenjin/getDeepLink.markdown Example of how to get deep link data using the tenjin.getDeepLink() function. ```lua local tenjin = require( "plugin.tenjin" ) local function tenjinDeepLinkListener( event ) -- Handle events here end -- Get deep link tenjin.getDeepLink( tenjinDeepLinkListener ) ``` -------------------------------- ### Facebook init example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/facebook-v4a/init.markdown This example demonstrates how to initialize the Facebook SDK and handle the fbinit event. It also includes logic to share a link after initialization. ```lua local facebook = require( "plugin.facebook.v4a" ) -- Check for a value inside the provided table local function valueInTable( t, valueToFind ) for k,v in pairs( t ) do if v == valueToFind then return true end end return false end local function shareLink( url ) local accessToken = facebook.getCurrentAccessToken() if accessToken == nil then facebook.login() elseif not valueInTable( accessToken.grantedPermissions, "publish_actions" ) then facebook.login( { "publish_actions" } ) else facebook.showDialog( "link", { link=url } ) end end local function facebookListener( event ) if ( "fbinit" == event.name ) then print( "Facebook initialized" ) -- Initialization complete; share a link shareLink( "https://www.coronalabs.com/" ) elseif ( "fbconnect" == event.name ) then if ( "session" == event.type ) then -- Handle login event and try to share the link again if needed elseif ( "dialog" == event.type ) then -- Handle dialog event end end end -- Set the "fbinit" listener to be triggered when initialization is complete facebook.init( facebookListener ) ``` -------------------------------- ### Get native property Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/type/NativeDisplayObject/getNativeProperty.markdown This example shows how to get the "allowsInlineMediaPlayback" property of a WebView. ```lua local webView = native.newWebView( 0, 0, display.contentWidth, display.contentHeight ) local allows = webView:getNativeProperty( "allowsInlineMediaPlayback" ) ``` -------------------------------- ### Basic Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/plugin/admob/show.markdown This example demonstrates how to initialize the AdMob plugin, load an interstitial ad, and then show it. ```lua local admob = require( "plugin.admob" ) -- AdMob listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Load an AdMob interstitial ad admob.load( "interstitial", { adUnitId="YOUR_ADMOB_AD_UNIT_ID" } ) end end -- Initialize the AdMob plugin admob.init( adListener, { appId="YOUR_ADMOB_APP_ID" } ) -- Sometime later, show the interstitial ad if ( admob.isLoaded( "interstitial" ) ) then admob.show( "interstitial" ) end ``` -------------------------------- ### metadata.json Example Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/native/plugin/submission.markdown Example of a metadata.json file containing core information about a plugin. ```json { "contact": "me@mycompany.com", "url": "http://www.mycompany.com", "pluginName": "plugin.mylibrary", "publisherId": "com.mycompany" } ``` -------------------------------- ### Example Usage Source: https://github.com/coronalabs/corona-docs/blob/master/markdown/api/library/audio/play.markdown This example demonstrates loading audio streams and sounds, and then playing them with various options. ```lua -- Completion listener function local function narrationFinished( event ) print( "Narration Finished on channel", event.channel ) if ( event.completed ) then print( "Narration completed playback naturally" ) else print( "Narration was stopped before completion" ) end end -- Load two audio streams and one sound local backgroundMusic = audio.loadStream( "backgroundMusic.m4a" ) local narrationSpeech = audio.loadStream( "narrationSpeech.wav" ) local laserSound = audio.loadSound( "laserBlast.wav" ) -- Play the background music on channel 1, loop infinitely, and fade in over 5 seconds local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1, fadein=5000 } ) -- Play the speech on any available channel, for 30 seconds at most, and invoke listener function when audio finishes local narrationChannel = audio.play( narrationSpeech, { duration=30000, onComplete=narrationFinished } ) -- Play the laser on any available channel local laserChannel = audio.play( laserSound ) ```