Vlang modules #17724
-
V是如何搜索其它模块文件的请帮忙能仔细说明,按照官方文档和中文文档介绍的在一级目录下没有问题例如: |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 6 replies
-
You have |
Beta Was this translation helpful? Give feedback.
-
由于翻译软件的问题我大概理解说的意思,我也看出来mymodule少了一个‘s’,可能是官方例子没有维护好,我的测试文件模块名是完全匹配的 |
Beta Was this translation helpful? Give feedback.
-
test/ pub fn hello_world() { fn main() { test/ pub fn hello_world() { fn main() { ` |
Beta Was this translation helpful? Give feedback.
-
V expects modules to be in a subdirectory which is named the same as the module name. All files in the subdirectory should have Also, put a file named Documentation on modules for V is here: https://github.com/vlang/v/blob/master/doc/docs.md#modules |
Beta Was this translation helpful? Give feedback.
-
Use
modules/a/a.v: module a
pub fn a() {
println('a')
} modules/b/b.v module b
pub fn b() {
println('b')
} src/mian.v import a
import b
fn main() {
a.a()
b.b()
}
Running this code:
|
Beta Was this translation helpful? Give feedback.
-
Personally, I am fine with just
It looks simpler, and works the same as having the |
Beta Was this translation helpful? Give feedback.
-
@JalonSolov 非常感谢你的耐心回复 |
Beta Was this translation helpful? Give feedback.
-
关于模块文件的搜索, 这里有个比较详细的文章 https://lydiandylin.gitbook.io/vlang/mu-lu/module#mo-kuai-sou-suo-lu-jing |
Beta Was this translation helpful? Give feedback.
Use
modules
instead ofmod
and addv.mod
, and it works correctly.modules/a/a.v:
modules/b/b.v
src/mian.v
v.mod
is an empty file.Running this code: