模块

模块,是一个 Silk源文件,包含了全局变量,函数和类的定义。
把相关的代码分配到一个模块文件里能让代码更有逻辑,更易懂。

假设有一个模块文件file1.si:

_gTest=0;
func test_module()
{
    print("this is test");
}

#Include指令
在自己的程序中引用包含其它模块文件,使用#include指令。上面的file1.si模块文件,我们通过下面的指令包含:
#include "file1.si" //包含file1.si

main()
{
        test_module();//直接调用file1.si里的函数
}

#include指令的搜索路径是当前目录(main函数文件所在目录),可以通过相对路径指定子目录或者上层目录:
#include "include/file.si"
#include "../base/test1.si"

也可以使用绝对路径包含模块文件:
#include "D:\\myworks\\test3.si"


模块文件可以重复包含多次,Silk会忽略重复的包含,只会导入一次。