yang131

导航

AngleScript语法

 

Class的使用要继承于Interface或者Mixin class.Mixinclass实际上就是类似于抽象类 ,它已经实现的,在子类里面不能实现,类似如下代码:

  

interface AInterface
{
	void DoSomething1();
	void DoSomething2();
}
//如果不用mixin 那么必须实现该接口的所有函数
mixin class ABase : AInterface
{
	
	void DoSomething1(){ print("DoSomething1 from ABase\r\n");}
	int data= 1;
}

class AChild : ABase
{
	//下面这一行如果实现会覆盖mixin类的函数
	//void DoSomething1(){ print("DoSomething1 from AChild\r\n");}
	void DoSomething2(){ print("DoSomething2 from AChild\r\n");}
}
class AChildC : AChild
{

	//该函数会覆盖父类的DoSomething
	void DoSomething2(){  
	//this.data = 23;
	//super::data = 33;
	
	//ABase::DoSomething1();	//报错无法访问
	AChild::DoSomething2();
	super.DoSomething2();
	print("DoSomething2 from AChildC\r\n");
	}
}

void main()
{
	print("hello");
	AChildC a;
	a.DoSomething1();
	a.DoSomething2();
}

 对于常用方式以上就够用。

还有几个要说明的:

object@ obj_h;//声明了一个指针为空,  object obj;//这样就可以你直接初始化,类似于c++ 

调用的时候不支持->而是通过"obj_h."的方式运行

 

函数对象:

  funcdef bool CALLBACK(int, int);
     A a;

    // Create the delegate for the A::Cmp class method
    CALLBACK @func = CALLBACK(a.Cmp);
  func(1,2);//这里直接调用
 字符串处理
void PrintFromCommon()
{
	print("Common\r\n");
	int b;
	b = 2;
	int c = 4;
	string str = b+c;
	string ss;
	ss += b;
	ss+= c;
	print(ss);
}

  如果要引用其他地方的as那么 #include"common.as",即可

反射和序列化,

 

lambda:

 bool result1 = func(valueA, valueB, function(a,b){ return a == b; });
 funcdef void A(int);
  funcdef void B(float);
  void func(A@) {}
  void func(B@) {}

  void main()
  {
    // Explicitly specify the type to tell the compiler that A is wanted
    func(function(int a) {});
  }

  

 

posted on 2024-05-11 18:13  NoNight  阅读(15)  评论(0编辑  收藏  举报