{"id":"cens-r/luauswitchcase","name":"luauswitchcase","scope":"cens-r","platform":"roblox","description":"Luau Switch-Case Implementation","version":"1.0.1","latest":"1.0.1","versions":["1.0.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"77c4df8afe19e5187cb6da2229d29a13702fc07c2bd184fc1e8ab54dd57ab392","likes":0,"downloads":0,"install":"forest install cens-r/luauswitchcase","url":"https://forest.dev/p/roblox/cens-r/luauswitchcase","files":"https://api.forest.dev/ai/package/roblox/cens-r/luauswitchcase/files","readme":"# LuauSwitchCase \r\nA basic switch-case module for Roblox Luau! Matches a given expression value to a case, then executes the case's function. If a case is not found then it will execute the default case if one was provided.   \r\n\r\n***Disclaimer: This module is NOT faster than doing if-else statements or using key-function dictionaries!***\r\n\r\n# Setup\r\n> Setup will probably change in the future to a single command\r\n\r\nYou can setup the SwitchCase module by requiring the module at the top of your script and unpacking the returned table.  \r\n*`PathToSwitchCase` should be the location where you've installed the SwitchCase module!*  \r\n```lua\r\nlocal PathToSwitchCase = game:GetService(\"ReplicatedStorage\"):WaitForChild(\"SwitchCase\")\r\nlocal switch, case, default = table.unpack(require(PathToSwitchCase))\r\n```\r\n\r\n# Features\r\n- Combine multiple expression checks into a single case (Multi-Argument Cases)\r\n- Chain Cases (Case-to-Case Format)\r\n- Support for both `break` and non-`break` functions.\r\n\r\n### Break Functions\r\nMost of the time you want to break from the switch loop when the expression value is matched to a case. This stops the switch statement in its tracks and tells it that nothing else needs to be checked/ran.  \r\nThats what the `close` function is used for! When the case is matched it lets the switch statement know to run the given function and exit the loop.\r\n```lua\r\n-- Syntax Example\r\ncase():\r\nclose(function)\r\n```\r\n\r\n### Non-Break Functions\r\nIn some cases you might not want to break out of the switch loop when your case is matched. Instead when matched, all cases (until another break function) will run.\r\nThat's when you'd use the `open` function, it lets the switch statement know it doesn't need to check cases any longer and to just run each function until it finds a break function.\r\n```lua\r\n-- Syntax Example\r\ncase():\r\nopen(function)\r\n```\r\n\r\n# Examples\r\n### Single-Argument Cases\r\n```lua\r\nlocal x = 2\r\n\r\nswitch (x) {\r\n case(1):\r\n  close(function ()\r\n   print(\"X is 1\")\r\n  end);\r\n  \r\n case(2):\r\n  close(function ()\r\n   print(\"X is 2\")\r\n  end);\r\n  \r\n  default:\r\n   close(function ()\r\n    print(\"Invalid X\")\r\n   end);\r\n}\r\n\r\n-- Prints: X is 2\r\n```\r\n\r\n### Multi-Argument Cases\r\n```lua\r\nlocal x = 2\r\n\r\nswitch (x) {\r\n case(1, 2):\r\n  close(function ()\r\n   print(\"X is either 1 or 2\")\r\n  end);\r\n  \r\n case(3, 4):\r\n  close(function ()\r\n   print(\"X is either 3 or 4\")\r\n  end);\r\n  \r\n  default:\r\n   close(function ()\r\n    print(\"Invalid X\")\r\n   end);\r\n}\r\n\r\n-- Prints: X is either 1 or 2\r\n```\r\n\r\n### Case-to-Case Format\r\n```lua\r\n local x = 2\r\n\r\nswitch (x) {\r\n case(1):\r\n case(2):\r\n  close(function ()\r\n   print(\"X is either 1 or 2\")\r\n  end);\r\n  \r\n case(3, 4):\r\n case(5, 6):\r\n  close(function ()\r\n   print(\"X is either 3, 4, 5, or 6\")\r\n  end);\r\n  \r\n  default:\r\n   close(function ()\r\n    print(\"Invalid X\")\r\n   end);\r\n}\r\n\r\n-- Prints: X is either 1 or 2\r\n```\r\n","readmeTruncated":false}