diff options
| author | ruki <[email protected]> | 2017-03-06 13:49:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-03-06 13:49:01 +0800 |
| commit | ae09c47c992e01e592309e5dad9b79beea5c154d (patch) | |
| tree | 6d0216af998450f7108b79811b4406e3ae878f64 /docs | |
| parent | 922adbe45795c0d19ef6465bfeddaa972fddbc5a (diff) | |
write task.run docs
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/manual.md | 54 | ||||
| -rwxr-xr-x | docs/zh/manual.md | 54 |
2 files changed, 108 insertions, 0 deletions
diff --git a/docs/manual.md b/docs/manual.md index 12aea7b08..620b2612f 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -4597,6 +4597,60 @@ end ###### task.run +- 运行指定任务 + +用于在自定义脚本、插件任务中运行[task](#task)定义的任务或插件,例如: + +```lua +task("hello") + on_run(function () + print("hello xmake!") + end) + +target("demo") + on_clean(function(target) + + -- 导入task模块 + import("core.project.task") + + -- 运行这个hello task + task.run("hello") + end) +``` + +我们还可以在运行任务事,增加参数传递,例如: + +```lua +task("hello") + on_run(function (arg1, arg2) + print("hello xmake: %s %s!", arg1, arg2) + end) + +target("demo") + on_clean(function(target) + + -- 导入task + import("core.project.task") + + -- {} 这个是给第一种选项传参使用,这里置空,这里在最后面传入了两个参数:arg1, arg2 + task.run("hello", {}, "arg1", "arg2") + end) +``` + +对于`task.run`的第二个参数,用于传递命令行菜单中的选项,而不是直接传入`function (arg, ...)`函数入口中,例如: + +```lua +-- 导入task +import("core.project.task") + +-- 插件入口 +function main(...) + + -- 运行内置的xmake配置任务,相当于:xmake f|config --plat=iphoneos --arch=armv7 + task.run("config", {plat="iphoneos", arch="armv7"}) +emd +``` + ##### core.project.project 用于获取当前工程的一些描述信息,也就是在`xmake.lua`工程描述文件中定义的配置信息,例如:[target](#target)、[option](#option)等。 diff --git a/docs/zh/manual.md b/docs/zh/manual.md index fa24f81a8..6add8a3bd 100755 --- a/docs/zh/manual.md +++ b/docs/zh/manual.md @@ -4597,6 +4597,60 @@ end ###### task.run +- 运行指定任务 + +用于在自定义脚本、插件任务中运行[task](#task)定义的任务或插件,例如: + +```lua +task("hello") + on_run(function () + print("hello xmake!") + end) + +target("demo") + on_clean(function(target) + + -- 导入task模块 + import("core.project.task") + + -- 运行这个hello task + task.run("hello") + end) +``` + +我们还可以在运行任务事,增加参数传递,例如: + +```lua +task("hello") + on_run(function (arg1, arg2) + print("hello xmake: %s %s!", arg1, arg2) + end) + +target("demo") + on_clean(function(target) + + -- 导入task + import("core.project.task") + + -- {} 这个是给第一种选项传参使用,这里置空,这里在最后面传入了两个参数:arg1, arg2 + task.run("hello", {}, "arg1", "arg2") + end) +``` + +对于`task.run`的第二个参数,用于传递命令行菜单中的选项,而不是直接传入`function (arg, ...)`函数入口中,例如: + +```lua +-- 导入task +import("core.project.task") + +-- 插件入口 +function main(...) + + -- 运行内置的xmake配置任务,相当于:xmake f|config --plat=iphoneos --arch=armv7 + task.run("config", {plat="iphoneos", arch="armv7"}) +emd +``` + ##### core.project.project 用于获取当前工程的一些描述信息,也就是在`xmake.lua`工程描述文件中定义的配置信息,例如:[target](#target)、[option](#option)等。 |
