Zero-K icon indicating copy to clipboard operation
Zero-K copied to clipboard

Don't use [[strings]]

Open sprunk opened this issue 4 years ago • 1 comments

Unit defs seem to have a convention where strings use [[this]] notation instead of "this" one or 'that' one. This causes problems when inexperienced modders try to work with those files. Consider:

weapons = {
    --[[ Let's comment out this lame weapon and add my own!
    {
        def = [[LAZOR]], -- acuelly ends here
        foo = 123,
        bar = [[BAZ]],
    },
    ]] -- Surely this is where my comment ends!
}

This is made especially bad by the fact that many syntax highlighters (in particular Notepad++) seem to get it wrong. The task is to find [[strings]] and convert them to "strings".


The only difference of [[ is multi-line strings, which isn't actually needed anywhere we use [[.

local x = "multi\nline\nstring" -- ugly

local y = "multi\n"
 .. "line\n" -- has to concatenate so CPU/GC pressure, also still ugly
 .. "string\n"

local z = "multi -- nope, syntax error, also this comment is actually part of the string
line
string"

local a = [[multi
line
string]]

sprunk avatar May 19 '22 22:05 sprunk

Unless there are edge cases that I'm unaware of, fixing this for non multi-line strings should be as simple as using the following regex: \[\[([^[]+)\]\] replacing the group with "$1"

But merging/reviewing the subsequent PR with ~20k changes in 500+ files will be a pain.

strategineer avatar Dec 03 '25 13:12 strategineer