-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselect_table.mdtlbl
More file actions
88 lines (77 loc) · 2.09 KB
/
select_table.mdtlbl
File metadata and controls
88 lines (77 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#**
* 关于快速生成选择表的工具
* 传入一段代码(DExp), 展开代码时的参数包含当前所在块号
* 例如可以快速创建变量存取表
*#
Builtin.BindSep! '.';
Builtin.MissesMatch! 1;
const SelectTable = (const match @ {
*Idx Count ChunkFunc {
take const(
SelectTable! Idx Count ChunkFunc (goto :breakout);
:breakout
);
}
*Idx Count ChunkFunc Breaker {
const match Count->op { [`__`] {
Builtin.Debug! Count;
Builtin.ExpandStack!;
Builtin.Err! "Cannot support non const eval select table count";
Builtin.Exit! 2;
} [?_0 >= 500] {
Builtin.Err! Builtin.Concat->[
"select table count too big: "
Builtin.Stringify->[Count]
];
} _ {} }
take*Chunk = 0;
match => @ { }
inline 0@ {
const match @ ([Chunk](
ChunkFunc! Chunk;
Breaker!;
)) => @ {}
take*Chunk = Chunk + 1;
match (*Chunk>=Count) { [1] {
Builtin.MakeSelect! Idx;
Builtin.StopRepeat!;
} _ {} }
}
}
});
# 例如以下示例代码, 绑定单位的同时将前五个绑定的单位记录在表中其它变量
SelectTable! i++ 5 (
_0.unit = @unit;
); # 类似 switch i { case 0: 0.unit = @unit; case 1: 1.unit = @unit; ... } i++;
i %= 5;
ubind @flare;
#* >>>
op mul __60 i 2
op add @counter @counter __60
set 0.unit @unit
jump 12 always 0 0
set 1.unit @unit
jump 12 always 0 0
set 2.unit @unit
jump 12 always 0 0
set 3.unit @unit
jump 12 always 0 0
set 4.unit @unit
jump 12 always 0 0
op add i i 1
op mod i i 5
ubind @flare
*#
# 有时会生成很大的变量存取表, 随处展开并不理想,
# 可以配合./function.mdtlbl 创建一个用于 存/取 变量的函数
#
#const ReadVars = Function[i (
# SelectTable! ..->i, 5, ([R:...result](
# R.unit = _0.unit;
# R.building = _0.building;
# )) ([B:..](B.Return!));
#)]->Call;
#
#take R = ReadVars[i];
#
#print R.unit", "R.building;