assemblyscript - 从 index.ts 以外的文件中导出类
问题描述
我制作了一个assembly/Vec3.ts
用此内容调用的文件:
/**
* @constructor
* @name pc.Vec3
* @classdesc A 3-dimensional vector.
* @description Creates a new Vec3 object.
* @param {Number} [x] The x value. If x is an array of length 3, the array will be used to populate all components.
* @param {Number} [y] The y value.
* @param {Number} [z] The z value.
* @example
* var v = new pc.Vec3(1, 2, 3);
*/
export class Vec3 {
x: number;
y: number;
z: number;
// AS is more strict than TS... need to replace all occuranves of this in PlayCanvasTS at some point
//constructor(x?: any, y?: number, z?: number)
constructor(x: number, y: number, z: number)
{
//if (x && x.length === 3) {
// this.x = x[0];
// this.y = x[1];
// this.z = x[2];
//} else {
// this.x = x || 0;
// this.y = y || 0;
// this.z = z || 0;
//}
this.x = x;
this.y = y;
this.z = z;
}
/**
* @function
* @name pc.Vec3#add
* @description Adds a 3-dimensional vector to another in place.
* @param {pc.Vec3} rhs The vector to add to the specified vector.
* @returns {pc.Vec3} Self for chaining.
* @example
* var a = new pc.Vec3(10, 10, 10);
* var b = new pc.Vec3(20, 20, 20);
*
* a.add(b);
*
* // Should output [30, 30, 30]
* console.log("The result of the addition is: " + a.toString());
*/
add(rhs: Vec3): Vec3 {
this.x += rhs.x;
this.y += rhs.y;
this.z += rhs.z;
return this;
}
/**
* @function
* @name pc.Vec3#add2
* @description Adds two 3-dimensional vectors together and returns the result.
* @param {pc.Vec3} lhs The first vector operand for the addition.
* @param {pc.Vec3} rhs The second vector operand for the addition.
* @returns {pc.Vec3} Self for chaining.
* @example
* var a = new pc.Vec3(10, 10, 10);
* var b = new pc.Vec3(20, 20, 20);
* var r = new pc.Vec3();
*
* r.add2(a, b);
* // Should output [30, 30, 30]
*
* console.log("The result of the addition is: " + r.toString());
*/
add2(lhs: Vec3, rhs: Vec3): Vec3 {
this.x = lhs.x + rhs.x;
this.y = lhs.y + rhs.y;
this.z = lhs.z + rhs.z;
return this;
}
}
然后通过构建它npm run asbuild
但是该文件只是被忽略并且不包含在untouched.wasm
.
是否可以从所有文件中导出类?
解决方案
目前,AssemblyScript 仅支持从入口文件 ( index.ts
) 全局导出。因此,您应该将所有实体重新导出到此文件。但这可能会在未来有所改善。请参阅此讨论:https ://github.com/AssemblyScript/assemblyscript/issues/464
推荐阅读
- c# - 避免在datagridview中重复
- chef-infra - 如何在 Chef 中禁止覆盖食谱版本?
- python - How to remove HTML tags from a list of texts in Python
- asp.net - Request to AWS reveals internal server IP address
- c# - Asp.net Core 中的 Ajax 助手标签文档
- mysql - 加入来自同一个表 mysql knex 的其他结果
- ios - UIRefreshControl Selector 不调用目标 c
- sql - 检查与 SQL Server 2000/2005 的连接详细信息
- spring-boot - 为什么千分尺不会停止向 datadog 发送数据并已经关闭?
- apache-kafka - 如何知道何时在 Kafka 中提交记录?