Search code examples
lualua-table

Why result of [[1]] is equal to '1' in Lua language?


[[1]]result in my terminal on macOS 10.15.7 with Lua 5.4.3

WithLua 5.4.3, On expression [[1]], And result is '1',type is string. I can not understand, and not find any useful info on Lua document.


Solution

  • https://www.lua.org/manual/5.4/manual.html#3.1

    It's introduced in section 3.1.

    Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on.

    The long format is usually used to write multiline literal strings and multiline comments.

    print([===[
    "Hello
    world!"]===])
    
    --[=[
    "Hello
    world!"
    ]=]