Browse Source

Merge pull request #40 from Rinkaa/patch-1

Add an example using `is_config` for conditional package requirements
ruki 4 years ago
parent
commit
b1437e233f
2 changed files with 30 additions and 0 deletions
  1. 15 0
      manual/conditions.md
  2. 15 0
      zh-cn/manual/conditions.md

+ 15 - 0
manual/conditions.md

@@ -249,6 +249,21 @@ if is_config("test", "hello1", "hello2") then
 end
 ```
 
+Can be used for conditional package requirements, eg. :
+
+```lua
+-- Add lua or luajit package requirements, depending on the lua_flavor option value
+option("lua_flavor")
+    set_showmenu(true)
+    set_values("luajit", "lua")
+option_end()
+if is_config("lua_flavor", "luajit") then
+    add_requires("luajit")
+elseif is_config("lua_flavor", "lua") then
+    add_requires("lua")
+end
+```
+
 Not only that, we can also set pattern matching rules to determine values, such as:
 
 ```lua

+ 15 - 0
zh-cn/manual/conditions.md

@@ -266,6 +266,21 @@ if is_config("test", "hello1", "hello2") then
 end
 ```
 
+可以用来根据配置值增加对应的依赖包,例如:
+
+```lua
+-- 根据lua_flavor的配置值,选择依赖lua还是luajit
+option("lua_flavor")
+    set_showmenu(true)
+    set_values("luajit", "lua")
+option_end()
+if is_config("lua_flavor", "luajit") then
+    add_requires("luajit")
+elseif is_config("lua_flavor", "lua") then
+    add_requires("lua")
+end
+```
+
 不仅如此,我们还可以设置模式匹配规则去判断值,例如:
 
 ```lua