Used to obtain information about the compiled language, generally used for the operation of code files.
::: tip API
language.extensions()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| table | Returns a table with file extensions as keys and language source types as values |
Get a list of code suffixes for all languages.
The results are as follows:
{
[".c"] = cc,
[".cc"] = cxx,
[".cpp"] = cxx,
[".m"] = mm,
[".mm"] = mxx,
[".swift"] = sc,
[".go"] = gc
}
::: tip API
language.targetkinds()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| table | Returns a table with target types as keys and lists of supported linkers as values |
Get a list of target types in all languages.
The results are as follows:
{
binary = {"ld", "gcld", "dcld"},
static = {"ar", "gcar", "dcar"},
shared = {"sh", "dcsh"}
}
::: tip API
language.sourcekinds()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| table | Returns a table with source file types as keys and file extensions or extension lists as values |
Get a list of source file types in all languages.
The results are as follows:
{
cc = ".c",
cxx = {".cc", ".cpp", ".cxx"},
mm = ".m",
mxx = ".mm",
sc = ".swift",
gc = ".go",
rc = ".rs",
dc = ".d",
as = {".s", ".S", ".asm"}
}
::: tip API
language.sourceflags()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| table | Returns a table with source file types as keys and compilation option name lists as values |
Load a list of source file compilation option names for all languages.
The results are as follows:
{
cc = {"cflags", "cxflags"},
cxx = {"cxxflags", "cxflags"},
...
}
::: tip API
language.load(name: <string>)
:::
| Parameter | Description |
|---|---|
| name | Required. Language name, e.g., "c++", "c" |
| Type | Description |
|---|---|
| language | Returns a language object, or nil if it doesn't exist |
Load a specific language object from the language name, for example:
local lang = language.load("c++")
if lang then
print(lang:name())
end
::: tip API
language.load_sk(sourcekind: <string>)
:::
| Parameter | Description |
|---|---|
| sourcekind | Required. Source file type, e.g., "cc", "cxx", "mm" |
| Type | Description |
|---|---|
| language | Returns a language object, or nil if it doesn't exist |
Load specific language objects from the source file type: cc, cxx, mm, mxx, sc, gc, as .., for example:
local lang = language.load_sk("cxx")
if lang then
print(lang:name())
end
::: tip API
language.load_ex(extension: <string>)
:::
| Parameter | Description |
|---|---|
| extension | Required. Source file extension, e.g., ".cpp", ".c" |
| Type | Description |
|---|---|
| language | Returns a language object, or nil if it doesn't exist |
Load specific language objects from the source file extension: .cc, .c, .cpp, .mm, .swift, .go .., for example:
local lang = language.load_ex(".cpp")
if lang then
print(lang:name())
end
::: tip API
language.sourcekind_of(filepath: <string>)
:::
| Parameter | Description |
|---|---|
| filepath | Required. Source file path |
| Type | Description |
|---|---|
| string | Returns the source file type, e.g., "cxx", "cc" |
That is, from a given source file path, get the type of source file it belongs to, for example:
print(language.sourcekind_of("/xxxx/test.cpp"))
The result is: cxx, which is the c++ type. For the corresponding list, see: language.sourcekinds