{"id":"chipioindustries/make-standalone","name":"make-standalone","scope":"chipioindustries","platform":"roblox","description":"Utility function for converting methods to standalone functions.","version":"1.0.7","latest":"1.0.7","versions":["1.0.3","1.0.5","1.0.7"],"license":"AGPL-3.0","licenseRating":"unsafe","licenseCaveats":["Strongest copyleft: even network use counts as distribution, so running this in a live game plausibly requires releasing your game's entire source under AGPL-3.0. Not recommended for closed-source projects.","License identified from the packaged LICENSE file; the manifest declared none."],"licenseVerified":true,"dependencies":{"osyrisrblx/t":{"version":"^3.0.0","alias":"t"}},"integrity":"c597a817d94fecdf143b16d8648a6af204dcd2bb3bfa8cf238c010a35c8f4565","likes":0,"downloads":0,"install":"forest install chipioindustries/make-standalone","url":"https://forest.dev/p/roblox/chipioindustries/make-standalone","files":"https://api.forest.dev/ai/package/roblox/chipioindustries/make-standalone/files","readme":"# makeStandalone\n\nmakeStandalone is a utility function that accepts a method and its object and returns a standalone function that can be called on its own or passed as a callback to another function.\n\n## Examples\n\nConnecting a class member to a signal:\n```lua\nlocal Class = require(script.Parent.Class)\nlocal makeStandalone = require(script.Parent.makeStandalone)\n\nlocal myClass = Class.new()\nlocal part = workspace.Part\nlocal standaloneAction = makeStandalone(myClass.doThing, myClass)\npart.Touched:Connect(standaloneAction)\n```\n\nPassing arguments:\n```lua\nlocal myObject = {}\nfunction myObject:doThing(a, b, c)\n\tprint(a, b, c) -- myObject, 1, 2\nend\nlocal standaloneAction = makeStandalone(myObject.doThing, myObject)\nstandaloneAction(1, 2)\n```\n\nConverting a Roblox Instance method:\n```lua\nlocal makeStandalone = require(script.Parent.makeStandalone)\nlocal part = workspace.Part\n\nlocal standaloneDestroy = makeStandalone(part.Destroy, part)\npart.Touched:Connect(standaloneDestroy)\n```\n\nI personally use this most often to let an object connect its methods to events:\n\n```lua\nlocal makeStandalone = require(script.Parent.makeStandalone)\n\nlocal Class = {}\nClass.__index = Class\n\nfunction Class.new(target)\n\tlocal self = setmetatable({\n\t\t_target = target;\n\t}, Class)\n\tself._standaloneDoThing = makeStandalone(self._doThing, self)\n\treturn self\nend\n\nfunction Class:init()\n\tself._connection = target.Touched:Connect(self._standaloneDoThing)\nend\n\nfunction Class:_doThing(hit)\n\tprint((\"target was touched by %s\"):format(tostring(hit)))\nend\n\nfunction Class:destroy()\n\tself._connection:Disconnect()\nend\n```","readmeTruncated":false}