ruki 6 месяцев назад
Родитель
Сommit
4d5c0b897b

+ 1 - 0
docs/api/index.md

@@ -17,5 +17,6 @@ outline: deep
 ## Scripts API
 
 - [Target Instance](/api/scripts/target_instance)
+- [Option Instance](/api/scripts/option_instance)
 - [Package Instance](/api/scripts/package_instance)
 - [Native Modules](/api/scripts/native_modules)

+ 52 - 0
docs/api/scripts/option_instance.md

@@ -0,0 +1,52 @@
+# Option Instance
+
+This page describes the interface for `option` of functions like `on_load()`, `on_check()` or `after_check()` of the [Configuration option](https://xmake.io/#/manual/configuration_option.md)
+
+## option:value
+
+- Get the value of the option
+
+## option:name
+
+- Get the name of the option
+
+## option:get
+
+- Get the values of the option by name
+
+```lua
+-- get the links
+option:get("links")
+-- get the defined macros
+option:get("defines")
+```
+
+## option:set
+
+- Set the values of the option by name.
+
+If you just want to add values use [option:add](#option-add).
+
+```lua
+-- set the links
+option:set("links", "sdl2")
+-- set the defined macros
+option:set("defines", "SDL_MAIN_HANDLED")
+-- set configvar
+option:set("configvar", option:name(), option:value(), {quote = false})
+```
+
+## option:add
+
+- Add to the values of the option by name
+
+```lua
+-- add links
+option:add("links", "sdl2")
+-- add defined macros
+option:add("defines", "SDL_MAIN_HANDLED")
+```
+
+::: tip NOTE
+The document here is still in progress, please be patient, you can also speed up the update of the document by sponsoring or submiting pr
+:::

+ 1 - 0
docs/config.ts

@@ -103,6 +103,7 @@ function descriptionApiGuide(): DefaultTheme.SidebarItem[] {
 function scriptsApiGuide(): DefaultTheme.SidebarItem[] {
   return [
     { text: 'Target Instance', link: '/target_instance' },
+    { text: 'Option Instance', link: '/option_instance' },
     { text: 'Package Instance', link: '/package_instance' },
     { text: 'Native Modules', link: '/native_modules' }
   ]

+ 1 - 0
docs/zh/api/index.md

@@ -16,5 +16,6 @@ outline: deep
 ## 脚本域 API {#scripts-api}
 
 - [目标实例](/zh/api/scripts/target_instance)
+- [选项实例](/zh/api/scripts/option_instance)
 - [包实例](/zh/api/scripts/package_instance)
 - [原生模块](/zh/api/scripts/native_modules)

+ 56 - 0
docs/zh/api/scripts/option_instance.md

@@ -0,0 +1,56 @@
+# 选项实例 {#option-instance}
+
+此页面描述了 [配置选项](https://xmake.io/#/zh-cn/manual/configuration_option.md) 的 `on_load()`、`on_check()` 或 `after_check()` 等函数的 `option` 接口
+
+
+## option:value
+
+- 获取选项的值
+
+## option:name
+
+- 获取选项的名字
+
+## option:get
+
+- 获取选项在描述域的配置值
+
+任何在描述域的 `set_xxx` 和 `add_xxx` 配置值都可以通过这个接口获取到。
+
+```lua
+-- get the links
+option:get("links")
+-- get the defined macros
+option:get("defines")
+```
+
+## option:set
+
+- 设置选项的配置值
+
+如果你想添加值可以用 [option:add](#option-add)。
+
+```lua
+-- set the links
+option:set("links", "sdl2")
+-- set the defined macros
+option:set("defines", "SDL_MAIN_HANDLED")
+-- set configvar
+option:set("configvar", option:name(), option:value(), {quote = false})
+```
+
+## option:add
+
+- 按名称添加到选项的值
+
+```lua
+-- add links
+option:add("links", "sdl2")
+-- add defined macros
+option:add("defines", "SDL_MAIN_HANDLED")
+```
+
+::: tip 注意
+此处文档还在进行中,请耐心等待,你也可以通过赞助或者提 pr 来加速文档的更新
+:::
+

+ 1 - 1
docs/zh/api/scripts/package_instance.md

@@ -1,4 +1,4 @@
-# 包实例
+# 包实例 {#package-instance}
 
 此页面描述了 [包依赖管理](https://xmake.io/#/zh-cn/manual/package_dependencies.md) 的 `on_load()`、`on_install()` 或 `on_test()` 等函数的 `package` 接口
 

+ 1 - 1
docs/zh/api/scripts/target_instance.md

@@ -1,4 +1,4 @@
-# 目标实例
+# 目标实例 {#target-instance}
 
 此页面描述了 [工程目标](https://xmake/.io#zh-cn/manual/project_target.md) 的 `on_load()`、`before_build()` 或 `after_install()` 等函数的 `target` 接口
 

+ 1 - 0
docs/zh/config.ts

@@ -140,6 +140,7 @@ function descriptionApiGuide(): DefaultTheme.SidebarItem[] {
 function scriptsApiGuide(): DefaultTheme.SidebarItem[] {
   return [
     { text: '目标实例', link: '/target_instance' },
+    { text: '选项实例', link: '/option_instance' },
     { text: '包实例', link: '/package_instance' },
     { text: '原生模块', link: '/native_modules' }
   ]