{"id":13496109,"url":"https://github.com/stein197/lua-switch","last_synced_at":"2026-01-28T11:48:17.312Z","repository":{"id":135171093,"uuid":"432458230","full_name":"stein197/lua-switch","owner":"stein197","description":"Switch statement for Lua","archived":false,"fork":false,"pushed_at":"2021-12-30T12:46:24.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-01T19:57:42.396Z","etag":null,"topics":[],"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/stein197.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-11-27T12:43:24.000Z","updated_at":"2022-09-22T01:49:38.000Z","dependencies_parsed_at":"2023-04-26T05:01:47.809Z","dependency_job_id":null,"html_url":"https://github.com/stein197/lua-switch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stein197%2Flua-switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stein197%2Flua-switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stein197%2Flua-switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stein197%2Flua-switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stein197","download_url":"https://codeload.github.com/stein197/lua-switch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222402977,"owners_count":16978768,"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":"2024-07-31T19:01:42.391Z","updated_at":"2026-01-28T11:48:17.283Z","avatar_url":"https://github.com/stein197.png","language":"Lua","funding_links":[],"categories":["Lua"],"sub_categories":[],"readme":"# Switch expression statement for Lua\n[![](https://img.shields.io/github/license/stein197/lua-switch)](LICENSE)\n![](https://img.shields.io/github/v/tag/stein197/lua-switch?label=Version)\n[![](https://img.shields.io/luarocks/v/stein197/lua-switch)](https://luarocks.org/modules/stein197/lua-switch)\n[![](https://img.shields.io/github/size/stein197/lua-switch/init.lua)](init.lua)\n\nThis package provides simple function named \"switch\" which could be used to emulate switch statement which does not exist in Lua but does in other languages. It  can handle default fallback.\n\n## Installation\nVia LuaRocks:\n```\nluarocks install lua-switch\n```\nOr just download and require `init.lua` file from this repo.\n\n## Usage\nJust require it in the code like in the example below:\n```lua\nlocal switch, default = require \"lua-switch\"()\nlocal var = \"b\"\nswitch (var) {\n\ta = 1; -- Use string key\n\t[1] = 2; -- Or numeric one\n\t[{\"b\", \"c\"}] = function () -- Use multiple values. Mostly functions will be used as code block\n\t\tprint \"Switch!\" -- Prints \"Switch!\"\n\tend;\n\t[default] = function () -- Use default fallback\n\t\tvar = 12\n\tend\n}\n-- Or even use it as expression\nlocal var = switch \"b\" {\n\ta = 1;\n\tb = 2;\n\tc = 3;\n\td = function ()\n\t\treturn 4; -- If you wish you can also use function blocks and return values from them\n\tend;\n}\nprint(var) -- Prints \"2\"\n```\n\n## Testing\nInstall luaunit package:\n```\nluarocks install luaunit\n```\nThen run from the console:\n```\nlua test.lua\n```\nMake sure that `luaunit` package can be required using `package.path` variable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstein197%2Flua-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstein197%2Flua-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstein197%2Flua-switch/lists"}