{"id":27946801,"url":"https://github.com/dmccuskey/lua-megaphone","last_synced_at":"2026-07-17T16:32:30.428Z","repository":{"id":25772874,"uuid":"29211165","full_name":"dmccuskey/lua-megaphone","owner":"dmccuskey","description":"in-app, global communication object","archived":false,"fork":false,"pushed_at":"2015-05-03T06:28:33.000Z","size":300,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T02:36:57.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmccuskey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-13T21:07:39.000Z","updated_at":"2018-09-28T08:25:56.000Z","dependencies_parsed_at":"2022-09-09T15:01:06.961Z","dependency_job_id":null,"html_url":"https://github.com/dmccuskey/lua-megaphone","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dmccuskey/lua-megaphone","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-megaphone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-megaphone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-megaphone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-megaphone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmccuskey","download_url":"https://codeload.github.com/dmccuskey/lua-megaphone/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-megaphone/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35588703,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-17T02:00:06.162Z","response_time":116,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T13:57:59.409Z","updated_at":"2026-07-17T16:32:30.345Z","avatar_url":"https://github.com/dmccuskey.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"## lua-megaphone ##\n\n\n### Overview ###\n\nThe Megaphone is to be used for inter-app communication\n\nThis is a singleton by nature and is global. Because it is global, any other component, view, etc can gain access to it to send and receive messages.\n\nAs any global object it should be used for only _well-defined events_!\n\n\n### Usage ###\n\nImport the object in a file for your app. Then embellish the object with \n\n=== Access ===\n\n```lua\n-- in a file in you app, say 'service/megaphone.lua'\n\n-- setup in app\nlocal Megaphone = require 'dmc_corona.dmc_megaphone'\n\n-- add message information to this object\n\nMegaphone.GAME_OVER_EVENT = 'game-over-event'\n\n-- then return\n\nreturn Megaphone\n```\n\n```lua\n-- in your core app file (eg, app controller, main, etc)\n-- import your version of Megaphone and make global\n\n_G.gMegaphone = require 'service.megaphone'\n\n```\n\n#### Event Listen ####\n\nUse method `listen` to receive global messages ( ie, like addEventListener() ):\n( the actual listener can be either an object or function )\n\n`gMegaphone:listen( \u003cobj or func\u003e )`\n\n```lua\n-- in one of your files/classes wanting to receive messages\n\nlocal f = function(event)\n  if event.type == gMegaphone.GAME_OVER_EVENT then \n    -- do game over stuff\n  end\nend\ngMegaphone:listen( f )\n```\n\n#### Sending Messages ####\n\nSend global messages by using method `say`. The first arg is the message type, the second optional arg is any data.\n\n`gMegaphone:say( \u003cmessage type\u003e, \u003cdata\u003e )`\n\ngMegaphone:say( gMegaphone.DATA_RENDER_REQUEST, { ...params...} )\n\n```lua\n-- in one of your files/classes dispatch a message\ngMegaphone:say( gMegaphone.GAME_OVER_EVENT )\n```\n\n#### Event Ignore ####\n\nUse method `ignore` to stop receiving global messages ( ie, like removeEventListener() ):\n( the actual listener should be same reference given in `listen` )\n\n`gMegaphone:ignore( \u003cobj or func\u003e )`\n\n```lua\nlocal f = function(event)\n  if event.type == gMegaphone.GAME_OVER_EVENT then \n    -- do game over stuff\n  end\nend\ngMegaphone:listen( f )\n\n-- later in app\ngMegaphone:ignore( f )\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmccuskey%2Flua-megaphone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmccuskey%2Flua-megaphone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmccuskey%2Flua-megaphone/lists"}