https://github.com/alurm/lua-match Skip to content Navigation Menu Toggle navigation Sign in * Product + GitHub Copilot Write better code with AI + Security Find and fix vulnerabilities + Actions Automate any workflow + Codespaces Instant dev environments + Issues Plan and track work + Code Review Manage code changes + Discussions Collaborate outside of code + Code Search Find more, search less Explore + All features + Documentation + GitHub Skills + Blog * Solutions By company size + Enterprises + Small and medium teams + Startups By use case + DevSecOps + DevOps + CI/CD + View all use cases By industry + Healthcare + Financial services + Manufacturing + Government + View all industries View all solutions * Resources Topics + AI + DevOps + Security + Software Development + View all Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners + Executive Insights * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} alurm / lua-match Public * Notifications You must be signed in to change notification settings * Fork 0 * Star 43 Minimalistic sum types and switches for Lua 43 stars 0 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights alurm/lua-match main BranchesTags [ ] Go to file Code Folders and files Name Name Last commit message Last commit date Latest commit History 5 Commits README.md README.md example.lua example.lua tag.lua tag.lua View all files Repository files navigation * README Minimalistic sum types and switches for Lua How? With a tagging function. A minimal usage example: local tag = dofile'tag.lua' local a_rectangle = tag('rectangle', { width = 10, height = 20 }) local switch = { rectangle = function(s) return print('Got a rectangle shape with the width of ' .. s.width) end, -- An optional default case. [false] = function() return print('Shape type is not known') end, } -- Will print "Got a rectangle shape with the width of 10". a_rectangle(switch) For a more thorough example, see example.lua. Tags are implemented by setting the __call metamethod on a table. The implementation (tag.lua) is so small, I'll just show it here in full: return function(tag, value) setmetatable(value, { __call = function(value, switch) local case = switch[tag] if case then return case(value) end local default = switch[false] if default then return default() end error('no match for tag ' .. tag) end }) return value end The license used for this project is MIT. About Minimalistic sum types and switches for Lua Resources Readme Activity Stars 43 stars Watchers 1 watching Forks 0 forks Report repository Releases No releases published Packages 0 No packages published Languages * Lua 100.0% Footer (c) 2025 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.