-
Notifications
You must be signed in to change notification settings - Fork 55
Working with lua
luarocks is the package manager for the Lua programming language. It is the easiest way to install each of the lua development tools described below.
brew install luarocksLanguage-server-protocol (LSP) enables content and library aware code completion in your editor.
In VSCode, enabling LSP-powered code completion is as easy as installing an extension. Read on to see how to get the same experience in vim or neovim.
Install lus-lsp with luarocks
See lua package manager if you haven't installed luarocks.
luarocks install lua-lspAdd this section to your coc-settings.json:
"languageserver": {
"lua": {
"command": "YOUR-PATH-TO/lua-language-server/bin/macOS/lua-language-server",
"args": ["-E", "YOUR-PATH-TO/lua-language-server/main.lua"],
"filetypes": ["lua"],
"rootPatterns": [".git/"],
"settings": {
"Lua": {
"workspace": {
"library": {
"YOUR-PATH-TO/hs-lsp-completion/build/stubs": true,
"YOUR-PATH-TO/neovim/runtime/lua": true,
"YOUR-PATH-TO/neovim/src/nvim/lua": true
},
"ignoreDir": [".cache"],
"maxPreload": 2000,
"preloadFileSize": 1000
},
"runtime": {
"version": "5.4.0"
},
"diagnostics": {
"enable": true,
"disable": ["lowercase-global", "unused-local"],
"globals": [
"hs",
"vim",
"it",
"describe",
"setup",
"teardown",
"before_each",
"after_each",
"pending",
"insulate"
]
},
"completion": {
"keywordSnippet": "Disable"
}
}
}
}
},
"diagnostic-languageserver.formatters": {
"lua-format": {
"command": "lua-format",
"args": ["-c", "~/.config/luaformatter/config.yaml"]
}
},
"diagnostic-languageserver.formatFiletypes": {
"lua": "lua-format"
},
If you're not using VS Code, there is still hope. Here's my setup with neovim:
luarocks install luacheck~/.luacheckrc config file:
-- vim:set ft=lua:
stds.hs = {
globals = {
hs = {other_fields = true},
spoon = {other_fields = true},
vim = {other_fields = true},
},
}
exclude_files = {"/Users/adamwagner/.luacheckrc"}
std = 'max+hs'
allow_defined = true
globals = {"hs", "rawrequire"}
ignore = {
"113",
"211/_.*", -- unused local var, except when prefixed with "_"
"212/_.*", -- unused argument, except when prefixed with "_"
"213/_.*", -- unused var in loop, except when prefixed with "_"
"212/self", -- ignore self
"631",
"614",
}
-- "423", -- Shadowing a loop variable
-- "211", -- Unused local variable
-- "212", -- Unused argument
-- "213", -- Unused loop variable
.luacheckrc inspiration:
- https://github.com/jaythomas/love-experiment/blob/1aa201e0e6b78639ba778f3e6a78c337f051fea6/.luacheckrc
- https://github.com/d954mas/indicator-2019/blob/fef7bb8a01fbb7addb6dafa7b29b18cd05a246dc/.luacheckrc
- https://github.com/Hugheth/shed-wars/blob/2eeff7353806226b48fed7eef11e3d3ea466417c/.luacheckrc
Add this section to your coc-settings.json:
"diagnostic-languageserver.filetypes": {
"lua": "luacheck"
},luarocks install luaformatterAdd this section to your coc-settings.json:
"diagnostic-languageserver.formatFiletypes": {
"lua": "lua-format"
},note: I haven't set this up yet, so can't vouch for it.
LOOP classes of debugging utilities for Lua.
A simple, embedabble CLI debugger for Lua.
Lua's stdlib is very thin, to say the least. Many common operations and patterns will require you to either find a library or write your own. The upside is a sort of charm that is earned by rolling your own low-level utils. Or, at minimum, researching available libraries and deciding which is best.
A work queue implementation written in Lua.
Queue implementation for Lua and PICO-8 Newer (2020)
🌏 Implement various containers, stack, queue, priority queue, heap, A* algorithms, etc. through Lua.
A lua library for creating pools of cached objects.
Yonaba/Moses is clearly the leading functional utility library for lua. I chose not to use Moses in stackline due to it's multi-file architecture. It's meant to be installed with luarocks, which increases installation complexity. Setting that aside, browsing the Moses sourcecode is generally instructive.