44 lines
1001 B
Plaintext
44 lines
1001 B
Plaintext
// Core 层 - 类系统
|
|
// 提供基础的类定义工具
|
|
|
|
// 简单的类创建函数
|
|
function class(base) {
|
|
local new_class = {};
|
|
|
|
if (base != null) {
|
|
// 继承基类
|
|
foreach (key, value in base) {
|
|
new_class[key] <- value;
|
|
}
|
|
new_class.base <- base;
|
|
}
|
|
|
|
// 创建实例的函数
|
|
new_class.constructor <- function() {}
|
|
|
|
new_class.new <- function(...) {
|
|
local instance = {};
|
|
|
|
// 复制类成员到实例
|
|
foreach (key, value in this) {
|
|
if (key != "new" && key != "constructor") {
|
|
instance[key] <- value;
|
|
}
|
|
}
|
|
|
|
// 设置元表实现继承
|
|
instance.setdelegate(this);
|
|
|
|
// 调用构造函数
|
|
if (this.constructor != null) {
|
|
instance.constructor.acall([instance].concat(vargv));
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
|
|
return new_class;
|
|
}
|
|
|
|
print("Class system loaded");
|