v2 / examples / dynamic_library_loader / modules / library / library.v
21 lines · 19 sloc · 769 bytes · fd269cad875a864190c5cf4f46190de20ef00319
Raw
1module library
2
3// add_1 is exported with the C name `add_1`.
4// It can be called by external programs, when the module is compiled
5// as a shared library.
6// It is exported, because the function is declared as public with `pub`.
7// The exported C name is `add_1`, because of the export: tag.
8// (Normally, the exported name is a V mangled version based on the module
9// name followed by __, followed by the fn name, i.e. it would have been
10// `library__add_1`, if not for the export: tag).
11@[export: 'add_1']
12pub fn add_1(x int, y int) int {
13 num := my_private_function(x + y)
14 println('hello from ${@FN} , num = ${num}')
15 return num
16}
17
18// this function is not exported and will not be visible to external programs.
19fn my_private_function(x int) int {
20 return 1 + x
21}
22