Search code examples
luaspecial-characters

What does the @ at sign mean in Lua?


I looked at Get containing path of lua file, and I can see that:

print(debug.getinfo(1).source)

... results with e.g.:

@/Users/e/test.lua

Apparently, as a path, this is a string - but what is the "at sign"/"at character" @ there for; what does it mean?

It was otherwise quite difficult finding anything useful related to this, by doing an internet search for Lua "at sign" (even with quotation marks)


Solution

  • It means that the function was defined in a file.

    From the Lua 5.4 Reference Manual: 4.7 The Debug Interface

    The fields of lua_Debug have the following meaning:

    source: the source of the chunk that created the function. If source starts with a '@', it means that the function was defined in a file where the file name follows the '@'. If source starts with a '=', the remainder of its contents describes the source in a user-dependent manner. Otherwise, the function was defined in a string where source is that string.

    The Lua manual lists other uses of @. For example warn("@off") can be used to turn off the emission of warnings.