Custom task task of xmake advanced features

2016/06/20 09:08
Reading number 287

Task is a new feature of xmake 2.0 and the core of plug-in development Hello xmake for plug-in development We briefly introduced the definition and use of the next task in

Of course, tasks can be used not only to write plug-ins, but also to write some simple custom tasks..

Let's look at the next simple task implementation:

 --Define a task named hello task("hello") --Entry for task operation on_run(function () --Show hello xmake! print("hello xmake!") end)

This is the simplest task. Compared with the plug-in task, it has less settings for set_menu. Of course, you can add it. OK, so you can call it from the command line..

This hello task has no set_menu set, so it can only be called in the custom script..

 target("demo") --Custom clean action on_clean(function(target) --Import task module import("core.project.task") --Run this hello task task.run("hello") end)

If you want to add parameter transmission, there are two ways:

  1. Add a command line option menu through set_menu, and access parameters through the option module (support command line and script parameter transmission)
  2. Parameter transfer directly through script

Let's take a look at the second one, which is relatively simple. It does not need to define the command line menu, but only needs the task definition and the caller to agree on the parameter rules:

 --Direct parameter transfer, {} This is used for parameter transfer of the first option, which is left blank --Here, two parameters are passed in at the end: arg1 and arg2 task.run("hello", {}, "arg1", "arg2")

How to obtain these two parameters?

 --Define a task named hello task("hello") --The entry for task running, defined as two parameters on_run(function (arg1, arg2) --Show hello xmake! print("hello xmake: %s %s!", arg1, arg2) end)

How simple is it? Of course, this parameter transfer method cannot be used for external parameter transfer through the command line, so it is generally used for calling some built-in tasks. For advanced tasks like plug-ins, the first parameter transfer method is required

For details, please refer to: Parameter configuration for plug-in development


Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top