Copyright © 2022-2025 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.2·
页面加载耗时 0.00 毫秒·物理内存 157.0MB ·虚拟内存 1438.9MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
Move 的基本数据类型包括: 整型 (u8, u64, u128)、布尔型 boolean 和地址 address。
Move 不支持字符串和浮点数。
整型包括 u8、u64 和 u128,我们通过下面的例子来理解整型:
script {
fun main() {
// define empty variable, set value later
let a: u8;
a = 10;
// define variable, set type
let a: u64 = 10;
// finally simple assignment
let a = 10;
// simple assignment with defined value type
let a = 10u128;
// in function calls or expressions you can use ints as constant values
if (a < 10) {};
// or like this, with type
if (a < 10u8) {}; // usually you don't need to specify type
}
}
as当需要比较值的大小或者当函数需要输入不同大小的整型参数时,你可以使用as运算符将一种整型转换成另外一种整型:
script {
fun main() {
let a: u8 = 10;
let b: u64 = 100;
// we can only compare same size integers
if (a == (b as u8)) abort 11;
if ((a as u64) == b) abort 11;
}
}
布尔类型就像编程语言那样,包含false和true两个值。
script {
fun main() {
// these are all the ways to do it
let b : bool; b = true;
let b : bool = true;
let b = true
let b = false; // here's an example with false
}
}
地址是区块链中交易发送者的标识符,转账和导入模块这些基本操作都离不开地址。
script {
fun main() {
let addr: address; // type identifier
// in this book I'll use {{sender}} notation;
// always replace `{{sender}}` in examples with VM specific address!!!
addr = {{sender}};
// in Diem's Move VM and Starcoin - 16-byte address in HEX
addr = 0x...;
// in dfinance's DVM - bech32 encoded address with `wallet1` prefix
addr = wallet1....;
}
}
需要对某些代码进行额外说明时,我们使用注释。注释是不参与执行的、旨在对相关代码进行描述和解释的文本块或文本行。单行注释script { fun main() { // this is a comment li ...