{"id":27946818,"url":"https://github.com/dmccuskey/lua-events-mixin","last_synced_at":"2025-05-07T13:58:08.514Z","repository":{"id":24962867,"uuid":"28380911","full_name":"dmccuskey/lua-events-mixin","owner":"dmccuskey","description":"Add event capability to your Lua objects (e.g., event dispatch/listeners)","archived":false,"fork":false,"pushed_at":"2015-05-03T06:26:55.000Z","size":332,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T13:58:02.640Z","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":"2014-12-23T06:06:01.000Z","updated_at":"2020-11-08T17:17:44.000Z","dependencies_parsed_at":"2022-08-23T08:31:34.875Z","dependency_job_id":null,"html_url":"https://github.com/dmccuskey/lua-events-mixin","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-events-mixin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-events-mixin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-events-mixin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmccuskey%2Flua-events-mixin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmccuskey","download_url":"https://codeload.github.com/dmccuskey/lua-events-mixin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252892523,"owners_count":21820647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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:58:07.903Z","updated_at":"2025-05-07T13:58:08.491Z","avatar_url":"https://github.com/dmccuskey.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"## lua-events-mixin ##\n\nAdd event capability to your Lua objects (event dispatch/listeners)\n\n\nThis module can add Event capability to any of your objects. It can be used either as a mixin class or by \"monkey-patching\" your object. It was designed to work with [lua-objects](https://github.com/dmccuskey/lua-objects) and has also been integrated in [dmc-objects](https://github.com/dmccuskey/dmc-objects) as a mixin.\n\n\n### Features ###\n\n* addEventListener\n* removeEventListener\n* dipatchEvent\n* custom events\n* unit tests\n\n\n### Examples ###\n\n#### Mixin Class ####\n\nThe project [dmc-objects](https://github.com/dmccuskey/dmc-objects) contains the `ObjectBase` sub-class which shows how to use this module as a mixin with multiple inheritance.\n\nHere it is in a nutshell:\n\n```lua\n-- import the events mixin module (adjust path for your project)\nlocal EventsMixModule = require 'dmc_lua.lua_events_mix'\n\n-- create ref to mixin (optional)\nlocal EventsMix = EventsMixModule.EventsMix\n\n-- do multiple inheritance !\nlocal ObjectBase = newClass( { Class, EventsMix } )\n\n\n-- Then call init method in your OO Framework construction phase\n\n-- with dmc-objects\n\tself:superCall( EventsMix, '__init__', ... )\n\n-- with other frameworks\n\tEventsMix.__init__( self, ... )\n\n\n-- When destroying, you can call __undoInit__\n\n-- with dmc-objects\n\tself:superCall( EventsMix, '__undoInit__' )\n\n-- with other frameworks\n\tEventsMix.__undoInit__( self )\n\n```\n\n\n#### Monkey Patching ####\n\n\n```lua\n--== Import module\n\nlocal EventsMixModule = require 'dmc_lua.lua_events_mix'\n\n\n--== Setup aliases, cleaner code\n\nlocal EventsMix = EventsMixModule.EventsMix\n\n\n\n--== Patch an object ==--\n\n-- create one for yourself (eg, with OOP library)\n\nlocal obj = {}  -- empty or create one from your OOP library\nobj = EventsMix.patch( obj ) -- returns object\n\n\n-- or have patch() create one for you\n\nlocal obj = EventsMix.patch()  -- returns a new object\n\n\n\n--== Methods\n\n-- obj.EVENT constant is automatically added to your object, it can be changed\n--\nobj:addEventListener( obj.EVENT, callback )\nobj:removeEventListener( obj.EVENT, callback )\n\nobj.EVENT = 'obj_event' -- EVENT can be changed\nobj.EVENT_NAME = 'my_custom_event_name' -- add this\nobj:dispatchEvent( obj.EVENT_NAME, data )\n\n\n\n--== Misc Methods\n\n-- set a function to turn on/off debug output (per object)\nobj:setDebug( boolean )\n\n-- set a function to create custom events\nobj:setEventFunc( func )\n\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmccuskey%2Flua-events-mixin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmccuskey%2Flua-events-mixin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmccuskey%2Flua-events-mixin/lists"}