简单示例
- 写一个简单的示例程序。
从HelloWorld说起
helloword.gs
void create()
{
write(HIR "create\n" NOR);
hello();
}
void hello()
{
write("helloworld\n");
}
void destruct()
{
write(HIB "destruct\n" NOR);
}
hello();
在上一章 的最后一节,我们已经可以启动driver并运行一些脚本。但当时并不关注语法,在这一小节中,将以helloworld为例介绍一个简单的示例(helloworld.gs)。
当我们用上一章的方法load_static
这个实例对象,可以看到结果将会是
helloworld
create
helloworld
就是说,当创建这个实例对象是,会先顺序执行调用的函数然后自动执行create函数。
此时,如果尝试在控制台上敲destruct_object(helloworld)
,会自动执行destruct函数。
这两个函数不是必须的,不写并不影响使用,在我们希望实例对象创建和销毁时(driver关闭时所有的对象会自动销毁)我们可以在这两个函数中添加方法。