Hacker News new | ask | show | jobs
by Rochus 1412 days ago
> a large lua game code base, over 4000 files, 1.5 million lines of code

Interesting; how do you manage to keep consistency? Do you have special tools to e.g. detect inadvertent global variables? I once wrote a Smalltalk VM in Lua (https://github.com/rochus-keller/Smalltalk/blob/master/Inter...) which is a much smaller code base, but even with this modest size I quickly would have lost track of e.g. scopes and names without tools I had to write myself (https://github.com/rochus-keller/LJTools).

2 comments

Most of the time nothing is used. The thing is that iterating is so quick, that you find the problems really fast.

Although, I've been using luacheck https://github.com/mpeterv/luacheck. It is quite nice, but you have to write down the global variables by hand on the config file.

Edit: Also, the vscode lua plugins have been getting quite good, and completion works to a certain extent.

It depends. You can also configure luacheck from within the file you are checking. For instance, in some of my lua code [1], I have:

    -- luacheck: globals init handler
    -- luacheck: ignore 611
The first line tells luacheck that the variables `init` and `handler` are globals, and the second line tells it to ignore lines that contain just whitespace (a quirk the text editor I use uses to manage indenting levels).

[1] https://github.com/spc476/port70/blob/master/port70/handlers...

Lua’s language server can be nice for detecting unwanted globals. It gives you a warning whenever you declare a global that starts in lowercase, which works nicely if you’re okay with using uppercase globals as a convention