{"id":42034614,"url":"https://github.com/apprehentice/attachment","last_synced_at":"2026-01-26T05:03:18.071Z","repository":{"id":28083212,"uuid":"31580801","full_name":"Apprehentice/attachment","owner":"Apprehentice","description":"A callback helper utility for LÖVE","archived":false,"fork":false,"pushed_at":"2015-04-03T23:46:36.000Z","size":160,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-02-27T05:25:32.428Z","etag":null,"topics":["event-handlers","lua"],"latest_commit_sha":null,"homepage":null,"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/Apprehentice.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-03-03T05:17:54.000Z","updated_at":"2015-04-03T23:46:36.000Z","dependencies_parsed_at":"2022-09-03T12:21:53.283Z","dependency_job_id":null,"html_url":"https://github.com/Apprehentice/attachment","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/Apprehentice/attachment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apprehentice%2Fattachment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apprehentice%2Fattachment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apprehentice%2Fattachment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apprehentice%2Fattachment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Apprehentice","download_url":"https://codeload.github.com/Apprehentice/attachment/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apprehentice%2Fattachment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28767015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T03:54:34.369Z","status":"ssl_error","status_checked_at":"2026-01-26T03:54:33.031Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["event-handlers","lua"],"created_at":"2026-01-26T05:03:13.710Z","updated_at":"2026-01-26T05:03:18.061Z","avatar_url":"https://github.com/Apprehentice.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"Attachment: A callback helper for LÖVE\n=====================================\nAttachment is a callback helper utility for the LÖVE framework. When initialized, Attachment will register all existing LÖVE callbacks with itself and then replace all of LÖVE's callbacks with its own. In addition, Attachment has its own event system so you can easily register all of your game's modules with LÖVE's callbacks.\n\n## Usage ##\nTo use Attachment, require it into your project, create an event handler, and attach some functions to it.\n\n### Creating an Event Handler ###\nCreating a Attachment event handler is as simple as calling the Attachment table.\n```Lua\nlocal attachment = require(\"attachment\")\nlocal handler = attachment()\n```\nFor simplicity, you may want to do this instead:\n```Lua\nlocal attachment = require(\"attachment\")()\n```\n\n### attaching ###\nThe function for attaching functions is used like this\n```Lua\nattachment:attach(\"event name\", function)\n```\n```Lua\nlocal attachment = require(\"attachment\")()\n\nattachment:attach(\"draw\", function()\n  love.graphics.setFont(love.graphics.newFont(12))\n  love.graphics.setColor(0, 255, 0)\n  love.graphics.print(\"Hello, World!\", 0, 0)\nend)\n```\nThe *attach* function returns the function that was added so that you may detach it later, if necessary.\n\nWith Attachment, you can also add all of an object or module's callbacks to a Attachment event handler by calling attachment:attachObject\n```Lua\nlocal attachment = require(\"attachment\")()\nlocal othermodule = require(\"othermodule\")\n\nattachment:attachObject(othermodule)\n```\nThis will have Attachment run through the object and register anything that looks like a LÖVE callback.\n\n### Unattaching ###\nTo detach a function from an event, do\n```Lua\nattachment:detach(\"event name\", function)\n```\nThis will run through the event called \"event name\" and remove the given function if it is found.\n\n### Calling ###\nYou can register your own events with Attachment if you'd like. To do so, simply attach a function to the desired event and then call the event somewhere in your code.\nFor example:\n```Lua\nlocal attachment = require(\"attachment\")()\nattachment:attach(\"foo\", function() print(\"bar\") end)\nattachment:call(\"foo\") -- Outputs \"bar\"\n```\n\n### Other Environments ###\nIf, for some reason, your main environment is not love, you can pass your environment to Attachment as the first argument when creating your Attachment event handler.\n```Lua\nlocal environment = require(\"environment\")\nlocal attachment = require(\"attachment\")(environment)\n```\nThis can be useful if, for example, you don't want Attachment to consume LÖVE's callbacks.\n```Lua\nlocal attachment = require(\"attachment\")({})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapprehentice%2Fattachment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapprehentice%2Fattachment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapprehentice%2Fattachment/lists"}