File tree Expand file tree Collapse file tree 1 file changed +0
-43
lines changed
Expand file tree Collapse file tree 1 file changed +0
-43
lines changed Original file line number Diff line number Diff line change @@ -141,49 +141,6 @@ PS: 说实话,我认为这个设计并不太好。
141141为什么是作用域顶层呢?实际上,Zig 将一个源码文件看作是一个容器。
142142:::
143143
144- ## ` usingnamespace `
145-
146- 关键字 ` usingnamespace ` 可以将一个容器中的所有 ` pub ` 声明混入到当前的容器中。
147-
148- 例如,可以使用 ` usingnamespace ` 将 ` std ` 标准库混入到 ` main.zig ` 这个容器中:
149-
150- ``` zig
151- const T = struct {
152- usingnamespace @import("std");
153- };
154- pub fn main() !void {
155- T.debug.print("Hello, World!\n", .{});
156- }
157- ```
158-
159- 注意:无法在结构体 ` T ` 内部直接使用混入的声明,需要使用 ` T.debug ` 这种方式才可以!
160-
161- ` usingnamespace ` 还可以使用 ` pub ` 关键字进行修饰,用于转发声明,这常用于组织 API 文件和 C 语言的 ` import ` 。
162-
163- ``` zig
164- pub usingnamespace @cImport({
165- @cInclude("epoxy/gl.h");
166- @cInclude("GLFW/glfw3.h");
167- @cDefine("STBI_ONLY_PNG", "");
168- @cDefine("STBI_NO_STDIO", "");
169- @cInclude("stb_image.h");
170- });
171- ```
172-
173- 相关的使用方法可以是这样的:
174-
175- ``` zig
176- pub usingnamespace @cImport({
177- @cInclude("xcb/xcb.h");
178- @cInclude("xcb/xproto.h");
179- });
180- ```
181-
182- 针对以上引入的头文件,我们可以这样使用 ` @This().xcb_generic_event_t ` 。
183-
184- > [ !IMPORTANT]
185- > 初次阅读此处感到困惑是正常的。在学习完后续概念后,此处内容将自然理解。
186-
187144## ` threadlocal `
188145
189146变量可以使用 ` threadlocal ` 修饰符,使得该变量在不同线程中拥有不同的实例:
You can’t perform that action at this time.
0 commit comments