此函数将只读取堆栈的第一个值(即"顶部")。它不会弹出该值,这意味着该函数或ds_stack_pop()将来仍可以读取该值。如果该堆栈为空,则该函数将返回未定义的常量,否则将返回堆栈中包含的实数或字符串值。
ds_stack_top(id);
参数 | 类型 | 描述 |
---|---|---|
id | DS Stack | 要读取的数据结构的ID。 |
Any (Data type value that is stored in the stack) or undefined
num = ds_stack_top(control_stack);
上述代码将从变量"control_stack"中索引的堆栈中读取值,并将返回值存储在变量"number"中。