Skip to content

Commit

Permalink
improve doc for xmake lua plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed May 10, 2017
1 parent d80214f commit 1d94a23
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
64 changes: 64 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ end

#### Run the Custom Lua Script

##### Run the given script

Write a simple lua script:

```lua
Expand All @@ -356,6 +358,68 @@ $ xmake lua /tmp/test.lua
You can also use `import` api to write a more advance lua script.
</p>

##### Run the builtin script

You can run `xmake lua -l` to list all builtin script name, for example:

```bash
$ xmake lua -l
scripts:
cat
cp
echo
versioninfo
...
```

And run them:

```bash
$ xmake lua cat ~/file.txt
$ xmake lua echo "hello xmake"
$ xmake lua cp /tmp/file /tmp/file2
$ xmake lua versioninfo
```

##### Run interactive commands (REPL)

Enter interactive mode:

```bash
$ xmake lua
> 1 + 2
3

> a = 1
> a
1

> for _, v in pairs({1, 2, 3}) do
>> print(v)
>> end
1
2
3
```
And we can `import` modules:
```bash
> task = import("core.project.task")
> task.run("hello")
hello xmake!
```
If you want to cancel multiline input, please input character `q`, for example:
```bash
> for _, v in ipairs({1, 2}) do
>> print(v)
>> q <-- cancel multiline and clear previous input
> 1 + 2
3
```
#### Generate IDE Project Files
##### Generate Makefile
Expand Down
72 changes: 72 additions & 0 deletions docs/zh/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ end

这个跟宏脚本类似,只是省去了导入导出操作,直接指定lua脚本来加载运行,这对于想要快速测试一些接口模块,验证自己的某些思路,都是一个不错的方式。

##### 运行指定的脚本文件

我们先写个简单的lua脚本:

```lua
Expand All @@ -369,6 +371,76 @@ $ xmake lua /tmp/test.lua
当然,你也可以像宏脚本那样,使用`import`接口导入扩展模块,实现复杂的功能。
</p>

##### 运行内置的脚本命令

你可以运行 `xmake lua -l` 来列举所有内置的脚本名,例如:

```bash
$ xmake lua -l
scripts:
cat
cp
echo
versioninfo
...
```

并且运行它们:

```bash
$ xmake lua cat ~/file.txt
$ xmake lua echo "hello xmake"
$ xmake lua cp /tmp/file /tmp/file2
$ xmake lua versioninfo
```

##### 运行交互命令 (REPL)

有时候在交互模式下,运行命令更加的方便测试和验证一些模块和api,也更加的灵活,不需要再去额外写一个脚本文件来加载。

我们先看下,如何进入交互模式:

```bash
# 不带任何参数执行,就可以进入
$ xmake lua
>

# 进行表达式计算
> 1 + 2
3

# 赋值和打印变量值
> a = 1
> a
1

# 多行输入和执行
> for _, v in pairs({1, 2, 3}) do
>> print(v)
>> end
1
2
3
```
我们也能够通过 `import` 来导入扩展模块:
```bash
> task = import("core.project.task")
> task.run("hello")
hello xmake!
```
如果要中途取消多行输入,只需要输入字符:`q` 就行了
```bash
> for _, v in ipairs({1, 2}) do
>> print(v)
>> q <-- 取消多行输入,清空先前的输入数据
> 1 + 2
3
```
#### 生成IDE工程文件
##### 简介
Expand Down

0 comments on commit 1d94a23

Please sign in to comment.