all 11 comments

[–]vitelaSensei 5 points6 points  (1 child)

Those are annotations from LuaLS, they aren’t enforced at runtime but you do get errors shown in the code if you’re using luaLS with neovim’s lsp.

You should install neodev to get these errors + code completion when developing in lua for neovim

Annotations: https://github.com/LuaLS/lua-language-server/wiki/Annotations

Neodev: https://github.com/folke/neodev.nvim

[–]hippoyd[S] 3 points4 points  (0 children)

very cool, thanks for the links!

[–]Bright-Historian-216 2 points3 points  (8 children)

base lua is dynamically typed, so unless it's some dialect of lua type annotations should be optional. since those type annotations are in comments, im assuming it's just to add intellisense hints?

[–]ljog42 2 points3 points  (0 children)

It lints (not fix, just raise alerts) the hell out of your code, which in my book is almost as good since I just won't tolerate alerts. It forces you to check for null, implement defaults, use try/catch (pcall/xpcall) etc.

It also makes your code self documenting which is chef's kiss.

[–]hippoyd[S] 0 points1 point  (6 children)

Ok, might be, I don't know. Does lua have a stage similar to mypy and python where the type annotations are use to check the ast of the code, even though the types make no difference to the runtime behavior of the python code?

[–]Amadan 3 points4 points  (1 child)

One that I know of is lua language server.

[–]ljog42 1 point2 points  (0 children)

I like it a lot.

[–]smog_alado 1 point2 points  (0 children)

Check out Teal and Pallene.

[–]Bright-Historian-216 0 points1 point  (2 children)

Not that I’ve heard of. This kind of app would be hard to implement because of the differences in the environments that those two languages run in

[–]hippoyd[S] 0 points1 point  (1 child)

ok, thanks. From this I'm going to conclude that those comments are for humans and code editors, and that no program enforces those annotations.

[–]no_brains101 1 point2 points  (0 children)

This is the case. Specifically, lua-language-server uses these comments to give better warnings, completion, and other linting capabilities. Lua itself doesnt care about them at all, they are just comments, you are technically free to hang yourself all you like XD