This page describes the option interface for functions like on_load(), on_check() or after_check() of the Configuration option.
In the script scope, you can operate various properties and configurations of the current option through the option parameter.
::: tip API
option:name()
:::
No parameters required for this function.
option("test")
on_check(function (option)
print(option:name()) -- output: test
end)
::: tip API
option:fullname()
:::
No parameters required for this function.
option("mymod::test")
on_check(function (option)
print(option:fullname()) -- output: mymod::test
end)
::: tip API
option:namespace()
:::
No parameters required for this function.
option("mymod::test")
on_check(function (option)
print(option:namespace()) -- output: mymod
end)
::: tip API
option:description()
:::
No parameters required for this function.
option("test")
set_description("This is a test option")
on_check(function (option)
print(option:description()) -- output: This is a test option
end)
::: tip API
option:value()
:::
No parameters required for this function.
option("demo")
set_default(true)
after_check(function (option)
local value = option:value()
if value then
print("demo option is enabled")
else
print("demo option is disabled")
end
end)
::: tip API
option:enabled()
:::
No parameters required for this function.
option("test")
after_check(function (option)
if option:enabled() then
print("Option is enabled")
end
end)
::: tip API
option:enable(enable: <boolean>)
:::
| Parameter | Description |
|---|---|
| enable | Whether to enable |
option("float")
after_check(function (option)
if option:dep("micro"):enabled() then
-- If micro option is enabled, disable float option
option:enable(false)
end
end)
::: tip API
option:set_value(value: <any>)
:::
| Parameter | Description |
|---|---|
| value | Option value |
option("test")
on_check(function (option)
-- Set option value to a specific value
option:set_value("custom_value")
end)
::: tip API
option:clear()
:::
No parameters required for this function.
option("test")
after_check(function (option)
-- Clear status, will recheck on next build
option:clear()
end)
::: tip API
option:get(key: <string>)
:::
| Parameter | Description |
|---|---|
| key | Configuration key name |
Any configuration values set by set_xxx and add_xxx in the description scope can be obtained through this interface.
option("test")
set_default(false)
set_category("option")
set_description("Test option")
add_defines("TEST_MODE")
add_links("testlib")
on_check(function (option)
-- Get various configurations
local default = option:get("default") -- false
local category = option:get("category") -- "option"
local description = option:get("description") -- "Test option"
local defines = option:get("defines") -- {"TEST_MODE"}
local links = option:get("links") -- {"testlib"}
-- Get type checking related configurations
local ctypes = option:get("ctypes") -- Get C type check list
local cfuncs = option:get("cfuncs") -- Get C function check list
local cincludes = option:get("cincludes") -- Get C header file check list
end)
::: tip API
option:set(key: <string>, value: <any>)
:::
| Parameter | Description |
|---|---|
| key | Configuration key name |
| value | Configuration value |
If you want to add values, you can use option:add.
option("test")
on_check(function (option)
-- Set link libraries
option:set("links", "sdl2")
-- Set predefined macros
option:set("defines", "SDL_MAIN_HANDLED")
-- Set configuration variables
option:set("configvar", option:name(), option:value(), {quote = false})
-- Set compilation flags
option:set("cxflags", "-O2", "-Wall")
-- Set header file search paths
option:set("includedirs", "/usr/include/sdl2")
-- Set library file search paths
option:set("linkdirs", "/usr/lib")
end)
::: tip NOTE
Any script scope configuration using option: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_default(false)option:set("default", false)
:::::: tip API
option:add(key: <string>, value: <any>)
:::
| Parameter | Description |
|---|---|
| key | Configuration key name |
| value | Value to add |
option("test")
on_check(function (option)
-- Add link libraries
option:add("links", "sdl2", "pthread")
-- Add predefined macros
option:add("defines", "DEBUG", "VERSION=1")
-- Add compilation flags
option:add("cxflags", "-g", "-O0")
-- Add header file search paths
option:add("includedirs", "/usr/local/include")
-- Add library file search paths
option:add("linkdirs", "/usr/local/lib")
-- Add system link libraries
option:add("syslinks", "dl", "m")
-- Add C type checks
option:add("ctypes", "wchar_t")
-- Add C function checks
option:add("cfuncs", "malloc", "free")
-- Add C header file checks
option:add("cincludes", "stdio.h", "stdlib.h")
end)
::: tip NOTE
Any script scope configuration using option: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_defines("DEBUG", "VERSION=1")option:add("defines", "DEBUG", "VERSION=1")
:::::: tip API
option:remove(key: <string>, value: <any>)
:::
| Parameter | Description |
|---|---|
| key | Configuration key name |
| value | Value to remove |
option("test")
on_check(function (option)
-- Remove specific link libraries
option:remove("links", "oldlib")
-- Remove specific predefined macros
option:remove("defines", "OLD_MACRO")
-- Remove specific compilation flags
option:remove("cxflags", "-Wall")
end)
::: tip API
option:deps()
:::
No parameters required for this function.
option("info")
add_deps("small", "micro")
after_check(function (option)
local deps = option:deps()
if deps then
for name, dep in pairs(deps) do
print("Dependency:", name, "enabled:", dep:enabled())
end
end
end)
::: tip API
option:dep(name: <string>)
:::
| Parameter | Description |
|---|---|
| name | Dependency name |
option("float")
add_deps("micro")
after_check(function (option)
local micro_dep = option:dep("micro")
if micro_dep and micro_dep:enabled() then
-- If micro dependency is enabled, disable current option
option:enable(false)
end
end)
::: tip API
option:orderdeps()
:::
No parameters required for this function.
option("test")
add_deps("dep1", "dep2")
after_check(function (option)
local orderdeps = option:orderdeps()
if orderdeps then
for i, dep in ipairs(orderdeps) do
print("Order dependency", i, ":", dep:name())
end
end
end)
::: tip API
option:extraconf(name: <string>, key: <string>)
:::
| Parameter | Description |
|---|---|
| name | Configuration name |
| key | Configuration key |
option("test")
add_csnippets("test_snippet", "int test() { return 1; }", {output = true})
on_check(function (option)
-- Check if snippet has output configuration
local has_output = option:extraconf("csnippets", "test_snippet", "output")
if has_output then
print("test_snippet has output configuration")
end
end)
::: tip TIP
on_check, after_check, the option parameter represents the current option instance being processedoption:get()option:set() and option:add()option:dep() to access dependent options and implement complex option logicoption:enabled() and option:enable()
:::