File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ title: 碎碎念
6
6
7
7
“碎碎念”是本站发布日常随笔的栏目,内容包括项目进展、小点子、有趣的讨论等。
8
8
9
+ - 2024-09-16: [ 凹语言打印源码位置信息] ( st0050.md )
9
10
- 2024-09-06: [ 凹语言开发案例分享: Pong游戏] ( st0049.md )
10
11
- 2024-09-05: [ 凹语言图书: µGo语言实现] ( st0048.md )
11
12
- 2024-08-28: [ 凹语言从G-Star毕业] ( st0047.md )
Original file line number Diff line number Diff line change
1
+ # 凹语言打印源码位置信息
2
+
3
+ - 时间:2024-09-16
4
+ - 撰稿:凹语言 开发组
5
+ - 转载请注明原文链接:[ https://wa-lang.org/smalltalk/st0050.html ] ( https://wa-lang.org/smalltalk/st0050.html )
6
+
7
+ ---
8
+
9
+ 首先祝大家中秋快乐!
10
+
11
+ ![ ] ( /st0005.png )
12
+
13
+ 凹语言发布了 [ v0.16.0] ( https://gitee.com/wa-lang/wa/releases/tag/v0.16.0 ) 中秋特别版本, 其中语言的变化是增加了源码位置信息的预定义常量.
14
+
15
+ - ` __package__ ` : 当前代码所在包路径, 无类型字符串常量
16
+ - ` __FILE__ ` : 当前代码所在文件名, 无类型字符串常量
17
+ - ` __LINE__ ` : 当前代码所在文件的行号, 无类型整数常量
18
+ - ` __func__ ` : 当前代码所在的具名函数或方法名字, 无类型字符串常量
19
+
20
+ 可以这样打印源码位置信息:
21
+
22
+ ``` wa
23
+ func main {
24
+ println("__package__:", __package__)
25
+ println("__FILE__:", __FILE__)
26
+ println("__LINE__:", __LINE__)
27
+ println("__func__:", __func__)
28
+ }
29
+ ```
30
+
31
+ 执行效果如下:
32
+
33
+ ```
34
+ $ wa run hello.wa
35
+ __package__: __main__
36
+ __FILE__: hello.wa
37
+ __LINE__: 4
38
+ __func__: main
39
+ ```
You can’t perform that action at this time.
0 commit comments