add_moduledirs
editadd_packagedirs
editadd_platformdirs
editadd_plugindirs
editadd_repositories
editadd_requireconfs
editadd_requires
editformat
string format(string formatstr[, ...])
Formatting a string
If you just want to format the string and don't output it, you can use this interface. This interface is equivalent to the string.format interface, just a simplified version of the interface name.
local s = format("hello %s", xmake)
See also
editget_config
editgetenv
edithas_config
edithas_package
editincludes
editipairs
for traversing arrays
This is lua's native built-in api. In xmake, it has been extended in its original behavior to simplify some of the daily lua traversal code.
First look at the default native notation:
for idx, val in ipairs({"a", "b", "c", "d", "e", "f"}) do
print("%d %s", idx, val)
end
The extension is written like the pairs interface, for example:
for idx, val in ipairs({"a", "b", "c", "d", "e", "f"}, function (v) return v:upper() end) do
print("%d %s", idx, val)
end
for idx, val in ipairs({"a", "b", "c", "d", "e", "f"}, function (v, a, b) return v:upper() .. a .. b end, "a", "b") do
print("%d %s", idx, val)
end
This simplifies the logic of the for
block code. For example, if I want to traverse the specified directory and get the file name, but not including the path, I can simplify the writing by this extension:
for _, filename in ipairs(os.dirs("*"), path.filename) do
-- ...
end
See also
editis_config
editis_cross
editis_kind
editpairs
Used to traverse the dictionary
This is lua's native built-in api. In xmake, it has been extended in its original behavior to simplify some of the daily lua traversal code.
First look at the default native notation:
local t = {a = "a", b = "b", c = "c", d = "d", e = "e", f = "f"}
for key, val in pairs(t) do
print("%s: %s", key, val)
end
This is sufficient for normal traversal operations, but if we get the uppercase for each of the elements it traverses, we can write:
for key, val in pairs(t, function (v) return v:upper() end) do
print("%s: %s", key, val)
end
Even pass in some parameters to the second function
, for example:
for key, val in pairs(t, function (v, a, b) return v:upper() .. a .. b end, "a", "b") do
print("%s: %s", key, val)
end
See also
editWrapping print terminal log
This interface is also the native interface of lua. xmake is also extended based on the original behavior, and supports: formatted output, multivariable output.
First look at the way native support:
print("hello xmake!")
print("hello", "xmake!", 123)
And also supports extended formatting:
print("hello %s!", "xmake")
print("hello xmake! %d", 123)
Xmake will support both types of writing at the same time, and the internal will automatically detect and select the output behavior.
See also
printf, vprint, cprint, dprint
editprintf
No line printing terminal log
Like the print interface, the only difference is that it doesn't wrap.