This page describes the interface for package of functions like on_load(), on_install() or on_test() of the Package Dependencies
::: tip API
package:name()
:::
No parameters required for this function.
::: tip API
package:get(key: <string>)
:::
| Parameter | Description |
|---|---|
| key | Configuration key name |
-- get the dependencies
package:get("deps")
-- get the links
package:get("links")
-- get the defined macros
package:get("defines")
::: tip API
package:set(key: <string>, value: <any>)
:::
| Parameter | Description |
|---|---|
| key | Configuration key name |
| value | Configuration value |
If you just want to add values use package:add
-- set the dependencies
package:set("deps", "python")
-- set the links
package:set("links", "sdl2")
-- set the defined macros
package:set("defines", "SDL_MAIN_HANDLED")
::: tip NOTE
Any script scope configuration using package:set("xxx", ...) is completely consistent with the corresponding set_xxx interface in the description scope. For specific parameter descriptions, you can directly refer to the corresponding set_xxx interface documentation in the description scope.
For example:
set_urls("https://github.com/madler/zlib/archive/$(version).tar.gz")package:set("urls", "https://github.com/madler/zlib/archive/$(version).tar.gz")
:::::: tip API
package:add(key: <string>, value: <any>)
:::
| Parameter | Description |
|---|---|
| key | Configuration key name |
| value | Value to add |
-- add dependencies
package:add("deps", "python")
-- add links
package:add("links", "sdl2")
-- add defined macros
package:add("defines", "SDL_MAIN_HANDLED")
::: tip NOTE
Any script scope configuration using package:add("xxx", ...) is completely consistent with the corresponding add_xxx interface in the description scope. For specific parameter descriptions, you can directly refer to the corresponding add_xxx interface documentation in the description scope.
For example:
add_deps("zlib", {configs = {shared = true}})package:add("deps", "zlib", {configs = {shared = true}})
:::::: tip API
package:license()
:::
No parameters required for this function.
Same as package:get("license")
::: tip API
package:description()
:::
No parameters required for this function.
Same as package:get("description")
::: tip API
package:plat()
:::
No parameters required for this function.
If the package is binary os.host is returned
::: tip API
package:arch()
:::
No parameters required for this function.
If the package is binary os.arch is returned
::: tip API
package:targetos()
:::
No parameters required for this function.
There are the same values as package:plat
::: tip API
package:targetarch()
:::
No parameters required for this function.
There are the same values as package:arch
::: tip API
package:is_plat(plat: <string>)
:::
| Parameter | Description |
|---|---|
| plat | Platform name |
-- Is the current platform android?
package:is_plat("android")
-- Is the current platform windows, linux or macosx?
package:is_plat("windows", "linux", "macosx")
::: tip API
package:is_arch(arch: <string>)
:::
| Parameter | Description |
|---|---|
| arch | Architecture name |
-- Is the current architecture x86
package:is_arch("x86")
-- Is the current architecture x64 or x86_64
package:is_arch("x64", "x86_64")
::: tip API
package:is_targetos()
:::
No parameters required for this function.
-- Is the currently targeted OS windows?
package:is_targetos("windows")
-- Is the currently targeted OS android or iphoneos?
package:is_targetos("android", "iphoneos")
::: tip API
package:is_targetarch()
:::
No parameters required for this function.
-- Is the currently targeted architecture x86
package:is_targetarch("x86")
-- Is the currently targeted architecture x64 or x86_64
package:is_targetarch("x64", "x86_64")
::: tip API
package:alias()
:::
No parameters required for this function.
If the user sets an alias like so:
add_requires("libsdl", {alias = "sdl"})
This alias can be retrieved by
-- returns "sdl"
package:alias()
::: tip API
package:urls()
:::
No parameters required for this function.
Retrieve the URLs set by:
add_urls("https://example.com/library-$(version).zip")
-- or so
set_urls("https://example.com/library-$(version).zip")
Then write this:
-- returns the table {"https://example.com/library-$(version).zip"}
package:urls()
::: tip API
package:dep(name: <string>)
:::
| Parameter | Description |
|---|---|
| name | Dependency name |
local python = package:dep("python")
-- returns "python"
python:name()
::: tip API
package:deps()
:::
No parameters required for this function.
-- prints the names of all dependencies
for _,dep in pairs(package:deps()) do
print(dep:name())
end
::: tip API
package:sourcehash()
:::
No parameters required for this function.
If the checksum is provided like so:
add_urls("https://example.com/library-$(version).zip", {alias = "example"})
add_versions("example:2.4.1", "29f9983cc7196e882c4bc3d23d7492f9c47574c7cf658afafe7d00c185429941")
You can retrieve the checksum like so:
-- returns "29f9983cc7196e882c4bc3d23d7492f9c47574c7cf658afafe7d00c185429941"
package:sourcehash("example")
-- or so
package:sourcehash(package:url_alias(package:urls()[1]))
::: tip API
package:kind()
:::
No parameters required for this function.
::: tip API
package:is_binary()
:::
No parameters required for this function.
::: tip API
package:is_toolchain()
:::
No parameters required for this function.
::: tip API
package:is_library()
:::
No parameters required for this function.
::: tip API
package:is_toplevel()
:::
No parameters required for this function.
::: tip API
package:is_thirdparty()
:::
No parameters required for this function.
package:config("debug"))::: tip API
package:is_debug()
:::
No parameters required for this function.
::: tip API
package:is_supported()
:::
No parameters required for this function.
::: tip API
package:debug()
:::
No parameters required for this function.
It's deprecated, please use package:is_debug instead
::: tip API
package:is_cross()
:::
No parameters required for this function.
::: tip API
package:cachedir()
:::
No parameters required for this function.
::: tip API
package:installdir()
:::
No parameters required for this function.
-- returns the installation directory
package:installdir()
-- returns the subdirectory include inside the installation directory
package:installdir("include")
-- returns the subdirectory include/files
package:installdir("include", "files")
::: tip API
package:scriptdir()
:::
No parameters required for this function.
::: tip API
package:envs()
:::
No parameters required for this function.
::: tip API
package:getenv()
:::
No parameters required for this function.
-- returns a table
package:getenv("PATH")
::: tip API
package:setenv()
:::
No parameters required for this function.
-- sets PATH to {"bin", "lib"}
package:setenv("PATH", "bin", "lib")
::: tip API
package:addenv()
:::
No parameters required for this function.
-- adds "bin" and "lib" to PATH
package:addenv("PATH", "bin", "lib")
::: tip API
package:versions()
:::
No parameters required for this function.
::: tip API
package:version()
:::
No parameters required for this function.
local version = package:version()
-- get the major version
version:major()
-- get the minor version
version:minor()
-- get the patch version
version:patch()
::: tip API
package:version_str()
:::
No parameters required for this function.
::: tip API
package:config()
:::
No parameters required for this function.
-- if configurations are set like so
add_require("example", {configs = {enable_x = true, value_y = 6}})
-- these values can be retrieved like so
-- returns true
package:config("enable_x")
-- returns 6
package:config("value_y")
::: tip API
package:config_set()
:::
No parameters required for this function.
package:config_set("enable_x", true)
package:config_set("value_y", 6)
::: tip API
package:configs()
:::
No parameters required for this function.
-- returns a table with the configuration names as keys and their values as values
local configs = package:configs()
local enable_x = configs["enable_x"]
local value_y = configs["value_y"]
::: tip API
package:buildhash()
:::
No parameters required for this function.
::: tip API
package:patches()
:::
No parameters required for this function.
-- returns a table with all patches
local patches = package:patches()
-- each element contains the keys "url" and "sha256"
local url = patches[1]["url"]
local sha256 = patches[1]["sha256"]
::: tip API
package:has_cfuncs()
:::
No parameters required for this function.
This should be used inside on_test like so:
on_test(function (package)
assert(package:has_cfuncs("foo"))
-- you can also add configs
assert(package:has_cfuncs("bar", {includes = "foo_bar.h"}))
assert(package:has_cfuncs("blob", {includes = "blob.h", configs = {defines = "USE_BLOB"}}))
-- you can even set the language
assert(package:has_cfuncs("bla", {configs = {languages = "c99"}}))
end)
::: tip API
package:has_cxxfuncs(funcs: <string|table>)
:::
| Parameter | Description |
|---|---|
| funcs | Function name or function name list |
This should be used inside on_test like so:
on_test(function (package)
assert(package:has_cxxfuncs("foo"))
-- you can also add configs
assert(package:has_cxxfuncs("bar", {includes = "foo_bar.hpp"}))
assert(package:has_cxxfuncs("blob", {includes = "blob.hpp", configs = {defines = "USE_BLOB"}}))
-- you can even set the language
assert(package:has_cxxfuncs("bla", {configs = {languages = "cxx17"}}))
end)
::: tip API
package:has_ctypes(types: <string|table>)
:::
| Parameter | Description |
|---|---|
| types | Type name or type name list |
This should be used inside on_test like so:
on_test(function (package)
assert(package:has_ctypes("foo"))
-- you can also add configs
assert(package:has_ctypes("bar", {includes = "foo_bar.h"}))
assert(package:has_ctypes("blob", {includes = "blob.h", configs = {defines = "USE_BLOB"}}))
-- you can even set the language
assert(package:has_ctypes("bla", {configs = {languages = "c99"}}))
end)
::: tip API
package:has_cxxtypes(types: <string|table>)
:::
| Parameter | Description |
|---|---|
| types | Type name or type name list |
This should be used inside on_test like so:
on_test(function (package)
assert(package:has_cxxtypes("foo"))
-- you can also add configs
assert(package:has_cxxtypes("bar", {includes = "foo_bar.hpp"}))
assert(package:has_cxxtypes("blob", {includes = "blob.hpp", configs = {defines = "USE_BLOB"}}))
-- you can even set the language
assert(package:has_cxxtypes("bla", {configs = {languages = "cxx17"}}))
end)
::: tip API
package:has_cincludes(includes: <string|table>)
:::
| Parameter | Description |
|---|---|
| includes | Include file or include file list |
This should be used in on_test like so:
on_test(function (package)
assert(package:has_cincludes("foo.h"))
end)
::: tip API
package:has_cxxincludes(includes: <string|table>)
:::
| Parameter | Description |
|---|---|
| includes | Include file or include file list |
This should be used in on_test like so:
on_test(function (package)
assert(package:has_cxxincludes("foo.hpp"))
end)
::: tip API
package:check_csnippets(snippets: <string|table>)
:::
| Parameter | Description |
|---|---|
| snippets | Code snippet or code snippet list |
This should be used in on_test like so:
on_test(function (package)
assert(package:check_csnippets({test = [[
#define USE_BLOB
#include <blob.h>
void test(int argc, char** argv) {
foo bar;
printf("%s", bar.blob);
}
]]}, {configs = {languages = "c99"}, includes = "foo.h"}))
end)
::: tip API
package:check_cxxsnippets(snippets: <string|table>)
:::
| Parameter | Description |
|---|---|
| snippets | Code snippet or code snippet list |
This should be used in on_test like so:
on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#define USE_BLOB
#include <blob.hpp>
void test(int argc, char** argv) {
foo bar();
std::cout << bar.blob;
}
]]}, {configs = {languages = "cxx11"}, includes = "foo.hpp"}))
end)
::: tip API
package:check_fcsnippets()
:::
No parameters required for this function.
see above