Skip to content

Instantly share code, notes, and snippets.

@wolf81
Last active September 9, 2025 01:29
Show Gist options
  • Select an option

  • Save wolf81/9483c2c4d4e79ca800e286c37d6c9cbe to your computer and use it in GitHub Desktop.

Select an option

Save wolf81/9483c2c4d4e79ca800e286c37d6c9cbe to your computer and use it in GitHub Desktop.
Sublime Text snippet for a Lua class prototype, invoke by typing `class`
<snippet>
<content><![CDATA[
local ${1:ClassName} = {}
$1.new = function()
$0
return setmetatable({
}, $1)
end
return setmetatable($1, {
__call = function(_, ...) return $1.new(...) end,
})
]]></content>
<tabTrigger>class</tabTrigger>
<description>Add a Lua class with private scope.</description>
<scope>source.lua</scope>
</snippet>
<snippet>
<content><![CDATA[
local M = {}
function M.$0()
end
return M
]]></content>
<tabTrigger>module</tabTrigger>
<description>Add a Lua module.</description>
<scope>source.lua</scope>
</snippet>
// Snippets for VS Code - store in .vscode/ directory at root of project.
{
"Lua Class Template": {
"prefix": "class",
"scope": "lua",
"body": [
"local ${1:ClassName} = {}",
"$1.new = function()",
"\t$0",
"\treturn setmetatable({",
"\t}, $1)",
"end",
"return setmetatable($1, {",
"\t__call = function(_, ...) return $1.new(...) end,",
"})"
],
"description": "Lua class-style metatable template"
},
"Lua Module Template": {
"prefix": "module",
"scope": "lua",
"body": [
"local M = {}",
"",
"function M.$0()",
"end",
"",
"return M"
],
"description": "Lua module with one function stub"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment