跳转到内容

导入代码

Tact 允许您导入 Tact 和 FunC 代码—任何给定的 .tact.fc/.func 文件都可以使用 import 关键字导入到您的项目中。

此外,Tact 编译器还拥有一套通用的标准库,这些标准库捆绑在 Tact 编译器中,但并不立即包含在 Tact 编译器中,请参阅 标准库概述

导入 Tact 代码

使用 import 语句并提供目标 .tact 文件的相对路径,可以导入任何 Tact 代码:

import "./relative/path/to/the/target/tact/file.tact";

也可以指定父目录 (../):

import "../subfolder/imported/file.tact";

导入 FunC 代码

可以直接导入用FunC代码编写的代码,就像导入Tact代码一样:

// Relative import
import "./relative/path/to/the/target/func/file.fc";
// Specifying parent directories
import "../subfolder/imported/func/file.fc";

但要使用此类文件中的函数,必须先将它们声明为 native 函数。 例如,当标准库 @stdlib/dns 使用 dns.fc FunC 文件时,它会将 FunC 函数映射到 Tact 函数,如下所示:

// FunC code located in a file right next to the current Tact one:
import "./dns.fc";
// Mapping function signatures from FunC to Tact:
@name(dns_string_to_internal)
native dnsStringToInternal(str: String): Slice?;

标准库

参见 标准库概述