宏¶
能少用就少用宏
#include
包含另一个文件的内容#import
#once
宏定义¶
对于某个宏定义:
#define
定义#redef
重写-
#undef
取消取消某个普通宏
#define XXX #undef XXX
取消某个宏函数
#define XXX(name) name #undef XXX(1) // XXX(N) 表示有 N 个参数
编译器内置宏定义以
#%
开头
#define linux #%config.os.linux
内置类型
名称 | b |
---|---|
int32 | |
uint32 | |
float32 | |
float32 |
控制语句¶
#if
#elif
#else
#end
#while
#while 1 <= 10
#for
#for i from 1 to 10
#.L1
建立一个 label#goto L1
跳转到 label L1
在宏中嵌入代码¶
#` code `#
#```
code1
code2
code3
```#
¶
#bof
将此处设为文件头 (忽略文件上方部分)#eof
将此处设为文件尾并结束预处理#;
当前宏结尾并开始下一个宏 (用于单行多个宏)
单行宏中的 while 和 if 无需 end 标记#
#
#
#
#
#
自定义宏¶
// #macro 宏不能出现在单行多个宏中
#macro Y-my_macro #undef xxx #; define xxx #%ARGS
#Y-my_macro 1 // xxx 被定义为 1
#Y-my_macro 2 // xxx 被定义为 2
#Y-my_macro 3 // xxx 被定义为 3
编译器自定义宏以
#X-
开头 用户自定义宏以#Y-
开头
¶
#replace rule0 "xxx" -> "yyy" // 将 xxx 替换为 yyy
#end rule0 // 删除 rule0
#replace rule1 /xxx$/ -> /yyy/ // 将行结尾的 xxx 替换为 yyy
#end rule1 // 删除 rule1
#set xxx = 3
#while xxx > 0
#if xxx == 1 #; break
#sub xxx 1
#end
#calc xxx -= 1
#set xxx = 3
#if xxx != 0
# eof
#end
#enwarning
开启某个警告#diswarning
关闭某个警告#warning
发出某个警告
#warning "提示信息"
#warning W1145 "提示信息"
定义警告编号,自定义的用WX
开头
#system curl -O http://example.com/xxx.lm
#import "xxx.lm"
不是哥们,这啥玩意啊?