xray16 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -1
- package/package.json +7 -4
- package/plugins/built_at_info.js +14 -0
- package/plugins/from_cast_utils.js +29 -0
- package/plugins/global_declarations_transform.js +20 -0
- package/plugins/inject_filename.js +20 -0
- package/plugins/plugins/built_at_info.js +12 -0
- package/plugins/plugins/from_cast_utils.js +27 -0
- package/plugins/plugins/global_declarations_transform.js +18 -0
- package/plugins/plugins/inject_filename.js +18 -0
- package/plugins/plugins/strip_lua_logger.js +51 -0
- package/plugins/plugins/transform_luabind_class/plugin.js +34 -0
- package/plugins/plugins/transform_luabind_class/transformation/class_declaration.js +141 -0
- package/plugins/plugins/transform_luabind_class/transformation/constants.js +4 -0
- package/plugins/plugins/transform_luabind_class/transformation/decorators.js +12 -0
- package/plugins/plugins/transform_luabind_class/transformation/errors.js +25 -0
- package/plugins/{transform_luabind_class/transformation/index.ts → plugins/transform_luabind_class/transformation/index.js} +5 -5
- package/plugins/plugins/transform_luabind_class/transformation/members/accessors.js +35 -0
- package/plugins/plugins/transform_luabind_class/transformation/members/constructor.js +56 -0
- package/plugins/plugins/transform_luabind_class/transformation/members/fields.js +36 -0
- package/plugins/plugins/transform_luabind_class/transformation/members/method.js +49 -0
- package/plugins/plugins/transform_luabind_class/transformation/new.js +8 -0
- package/plugins/plugins/transform_luabind_class/transformation/setup.js +76 -0
- package/plugins/plugins/transform_luabind_class/transformation/super.js +65 -0
- package/plugins/plugins/transform_luabind_class/transformation/utils.js +67 -0
- package/plugins/plugins/utils/diagnostics.js +17 -0
- package/plugins/strip_lua_logger.js +53 -0
- package/plugins/transform_luabind_class/plugin.js +36 -0
- package/plugins/transform_luabind_class/transformation/class_declaration.js +147 -0
- package/plugins/transform_luabind_class/transformation/constants.js +7 -0
- package/plugins/transform_luabind_class/transformation/decorators.js +16 -0
- package/plugins/transform_luabind_class/transformation/errors.js +28 -0
- package/plugins/transform_luabind_class/transformation/index.js +21 -0
- package/plugins/transform_luabind_class/transformation/members/accessors.js +39 -0
- package/plugins/transform_luabind_class/transformation/members/constructor.js +61 -0
- package/plugins/transform_luabind_class/transformation/members/fields.js +41 -0
- package/plugins/transform_luabind_class/transformation/members/method.js +56 -0
- package/plugins/transform_luabind_class/transformation/new.js +12 -0
- package/plugins/transform_luabind_class/transformation/setup.js +81 -0
- package/plugins/transform_luabind_class/transformation/super.js +72 -0
- package/plugins/transform_luabind_class/transformation/utils.js +77 -0
- package/plugins/utils/diagnostics.js +22 -0
- package/types/index.d.ts +28 -0
- package/{src → types}/xr_global.d.ts +35 -0
- package/{src → types}/xr_lib/xr_fs.d.ts +8 -1
- package/{src → types}/xr_object/xr_client_object.d.ts +31 -17
- package/{src → types}/xr_object/xr_server_object.d.ts +2 -0
- package/plugins/built_at_info.ts +0 -18
- package/plugins/from_cast_utils.ts +0 -34
- package/plugins/global_declarations_transform.ts +0 -24
- package/plugins/inject_filename.ts +0 -22
- package/plugins/strip_lua_logger.ts +0 -73
- package/plugins/transform_luabind_class/plugin.ts +0 -51
- package/plugins/transform_luabind_class/transformation/class_declaration.ts +0 -226
- package/plugins/transform_luabind_class/transformation/constants.ts +0 -4
- package/plugins/transform_luabind_class/transformation/decorators.ts +0 -16
- package/plugins/transform_luabind_class/transformation/errors.ts +0 -31
- package/plugins/transform_luabind_class/transformation/members/accessors.ts +0 -48
- package/plugins/transform_luabind_class/transformation/members/constructor.ts +0 -107
- package/plugins/transform_luabind_class/transformation/members/fields.ts +0 -53
- package/plugins/transform_luabind_class/transformation/members/method.ts +0 -70
- package/plugins/transform_luabind_class/transformation/new.ts +0 -14
- package/plugins/transform_luabind_class/transformation/setup.ts +0 -128
- package/plugins/transform_luabind_class/transformation/super.ts +0 -92
- package/plugins/transform_luabind_class/transformation/utils.ts +0 -90
- package/plugins/utils/diagnostics.ts +0 -24
- package/src/index.d.ts +0 -63
- /package/{src → types}/xr_constant.d.ts +0 -0
- /package/{src → types}/xr_core.d.ts +0 -0
- /package/{src → types}/xr_lib/xr_math.d.ts +0 -0
- /package/{src → types}/xr_lib/xr_utils.d.ts +0 -0
- /package/{src → types}/xr_luabind.d.ts +0 -0
- /package/{src → types}/xr_map/xr_map.d.ts +0 -0
- /package/{src → types}/xr_object/xr_action.d.ts +0 -0
- /package/{src → types}/xr_object/xr_alife.d.ts +0 -0
- /package/{src → types}/xr_object/xr_anomaly.d.ts +0 -0
- /package/{src → types}/xr_object/xr_artefact.d.ts +0 -0
- /package/{src → types}/xr_object/xr_creature.d.ts +0 -0
- /package/{src → types}/xr_object/xr_dialog.d.ts +0 -0
- /package/{src → types}/xr_object/xr_item.d.ts +0 -0
- /package/{src → types}/xr_object/xr_level.d.ts +0 -0
- /package/{src → types}/xr_object/xr_physic.d.ts +0 -0
- /package/{src → types}/xr_object/xr_quest.d.ts +0 -0
- /package/{src → types}/xr_online/xr_multiplayer.d.ts +0 -0
- /package/{src → types}/xr_sound/xr_sound.d.ts +0 -0
- /package/{src → types}/xr_type/xr_enums.d.ts +0 -0
- /package/{src → types}/xr_type/xr_type.d.ts +0 -0
- /package/{src → types}/xr_ui/README.md +0 -0
- /package/{src → types}/xr_ui/demo/CServerList.png +0 -0
- /package/{src → types}/xr_ui/demo/CUI3tButton.png +0 -0
- /package/{src → types}/xr_ui/demo/CUICheckButton.png +0 -0
- /package/{src → types}/xr_ui/demo/CUIComboBox.png +0 -0
- /package/{src → types}/xr_ui/demo/CUICustomEdit.png +0 -0
- /package/{src → types}/xr_ui/demo/CUIStatic.png +0 -0
- /package/{src → types}/xr_ui/demo/CUITrackBar.png +0 -0
- /package/{src → types}/xr_ui/xr_ui_core.d.ts +0 -0
- /package/{src → types}/xr_ui/xr_ui_interface.d.ts +0 -0
|
@@ -26,6 +26,8 @@ declare module "xray16" {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
+
* Class to link client side object implementation and wrap it with custom lua side logics.
|
|
30
|
+
*
|
|
29
31
|
* @source C++ class object_binder
|
|
30
32
|
* @customConstructor object_binder
|
|
31
33
|
* @group xr_client_object
|
|
@@ -253,7 +255,7 @@ declare module "xray16" {
|
|
|
253
255
|
*/
|
|
254
256
|
public set_callback(
|
|
255
257
|
type: TXR_callbacks["trade_sell_buy_item"],
|
|
256
|
-
cb?: ((item: game_object, money_direction: boolean, money: number) => void) | null,
|
|
258
|
+
cb?: ((this: void, item: game_object, money_direction: boolean, money: number) => void) | null,
|
|
257
259
|
object?: object_binder | null
|
|
258
260
|
): void;
|
|
259
261
|
|
|
@@ -264,7 +266,7 @@ declare module "xray16" {
|
|
|
264
266
|
*/
|
|
265
267
|
public set_callback(
|
|
266
268
|
type: TXR_callbacks["zone_enter"],
|
|
267
|
-
cb?: ((zone: game_object, object: game_object) => void) | null,
|
|
269
|
+
cb?: ((this: void, zone: game_object, object: game_object) => void) | null,
|
|
268
270
|
object?: object_binder | null
|
|
269
271
|
): void;
|
|
270
272
|
|
|
@@ -273,7 +275,7 @@ declare module "xray16" {
|
|
|
273
275
|
*/
|
|
274
276
|
public set_callback(
|
|
275
277
|
type: TXR_callbacks["zone_exit"],
|
|
276
|
-
cb?: ((zone: game_object, object: game_object) => void) | null,
|
|
278
|
+
cb?: ((this: void, zone: game_object, object: game_object) => void) | null,
|
|
277
279
|
object?: object_binder | null
|
|
278
280
|
): void;
|
|
279
281
|
|
|
@@ -286,7 +288,7 @@ declare module "xray16" {
|
|
|
286
288
|
*/
|
|
287
289
|
public set_callback(
|
|
288
290
|
type: TXR_callbacks["death"],
|
|
289
|
-
cb?: (target: game_object, killer: game_object) => void,
|
|
291
|
+
cb?: (this: void, target: game_object, killer: game_object) => void,
|
|
290
292
|
object?: object_binder
|
|
291
293
|
): void;
|
|
292
294
|
|
|
@@ -295,7 +297,7 @@ declare module "xray16" {
|
|
|
295
297
|
*/
|
|
296
298
|
public set_callback(
|
|
297
299
|
type: TXR_callbacks["patrol_path_in_point"],
|
|
298
|
-
cb?: ((object: game_object, action_type: number, point_index: number) => void) | null,
|
|
300
|
+
cb?: ((this: void, object: game_object, action_type: number, point_index: number) => void) | null,
|
|
299
301
|
object?: object_binder | null
|
|
300
302
|
): void;
|
|
301
303
|
|
|
@@ -306,7 +308,7 @@ declare module "xray16" {
|
|
|
306
308
|
*/
|
|
307
309
|
public set_callback(
|
|
308
310
|
type: TXR_callbacks["inventory_info"],
|
|
309
|
-
cb?: ((npc: game_object, info_id: string) => void) | null,
|
|
311
|
+
cb?: ((this: void, npc: game_object, info_id: string) => void) | null,
|
|
310
312
|
object?: object_binder | null
|
|
311
313
|
): void;
|
|
312
314
|
|
|
@@ -317,7 +319,7 @@ declare module "xray16" {
|
|
|
317
319
|
*/
|
|
318
320
|
public set_callback(
|
|
319
321
|
type: TXR_callbacks["task_state"],
|
|
320
|
-
cb?: ((task: CGameTask, state: TXR_TaskState) => void) | null,
|
|
322
|
+
cb?: ((this: void, task: CGameTask, state: TXR_TaskState) => void) | null,
|
|
321
323
|
object?: object_binder | null
|
|
322
324
|
): void;
|
|
323
325
|
|
|
@@ -328,12 +330,12 @@ declare module "xray16" {
|
|
|
328
330
|
*/
|
|
329
331
|
public set_callback(
|
|
330
332
|
type: TXR_callbacks["use_object"],
|
|
331
|
-
cb?: ((object: game_object) => void) | null,
|
|
333
|
+
cb?: ((this: void, object: game_object) => void) | null,
|
|
332
334
|
object?: object_binder | null
|
|
333
335
|
): void;
|
|
334
336
|
public set_callback(
|
|
335
337
|
type: TXR_callbacks["use_object"],
|
|
336
|
-
cb?: ((object: game_object, who: game_object) => void) | null,
|
|
338
|
+
cb?: ((this: void, object: game_object, who: game_object) => void) | null,
|
|
337
339
|
object?: object_binder | null
|
|
338
340
|
): void;
|
|
339
341
|
|
|
@@ -342,7 +344,16 @@ declare module "xray16" {
|
|
|
342
344
|
*/
|
|
343
345
|
public set_callback(
|
|
344
346
|
type: TXR_callbacks["hit"],
|
|
345
|
-
cb?:
|
|
347
|
+
cb?:
|
|
348
|
+
| ((
|
|
349
|
+
this: void,
|
|
350
|
+
object: game_object,
|
|
351
|
+
damage: number,
|
|
352
|
+
direction: vector,
|
|
353
|
+
who: game_object,
|
|
354
|
+
bone_id: number
|
|
355
|
+
) => void)
|
|
356
|
+
| null,
|
|
346
357
|
object?: object_binder | null
|
|
347
358
|
): void;
|
|
348
359
|
|
|
@@ -385,7 +396,7 @@ declare module "xray16" {
|
|
|
385
396
|
*/
|
|
386
397
|
public set_callback(
|
|
387
398
|
type: TXR_callbacks["helicopter_on_point"],
|
|
388
|
-
cb?: ((distance: number, current_position: vector, vertex_id: number) => void) | null,
|
|
399
|
+
cb?: ((this: void, distance: number, current_position: vector, vertex_id: number) => void) | null,
|
|
389
400
|
object?: object_binder | null
|
|
390
401
|
): void;
|
|
391
402
|
|
|
@@ -394,7 +405,7 @@ declare module "xray16" {
|
|
|
394
405
|
*/
|
|
395
406
|
public set_callback(
|
|
396
407
|
type: TXR_callbacks["helicopter_on_hit"],
|
|
397
|
-
cb?: ((damage: number, impulse: number, hit_type: number, who_id: number) => void) | null,
|
|
408
|
+
cb?: ((this: void, damage: number, impulse: number, hit_type: number, who_id: number) => void) | null,
|
|
398
409
|
object?: object_binder | null
|
|
399
410
|
): void;
|
|
400
411
|
|
|
@@ -403,7 +414,7 @@ declare module "xray16" {
|
|
|
403
414
|
*/
|
|
404
415
|
public set_callback(
|
|
405
416
|
type: TXR_callbacks["on_item_take"],
|
|
406
|
-
cb?: ((
|
|
417
|
+
cb?: ((this: void, object: game_object, item: game_object) => void) | null,
|
|
407
418
|
object?: object_binder | null
|
|
408
419
|
): void;
|
|
409
420
|
|
|
@@ -412,7 +423,7 @@ declare module "xray16" {
|
|
|
412
423
|
*/
|
|
413
424
|
public set_callback(
|
|
414
425
|
type: TXR_callbacks["on_item_drop"],
|
|
415
|
-
cb?: ((
|
|
426
|
+
cb?: ((this: void, object: game_object, item: game_object) => void) | null,
|
|
416
427
|
object?: object_binder | null
|
|
417
428
|
): void;
|
|
418
429
|
|
|
@@ -421,7 +432,7 @@ declare module "xray16" {
|
|
|
421
432
|
*/
|
|
422
433
|
public set_callback(
|
|
423
434
|
type: TXR_callbacks["script_animation"],
|
|
424
|
-
cb?: ((skip_multi_anim_check?: boolean) => void) | null,
|
|
435
|
+
cb?: ((this: void, skip_multi_anim_check?: boolean) => void) | null,
|
|
425
436
|
object?: object | null
|
|
426
437
|
): void;
|
|
427
438
|
|
|
@@ -436,7 +447,7 @@ declare module "xray16" {
|
|
|
436
447
|
*/
|
|
437
448
|
public set_callback(
|
|
438
449
|
type: TXR_callbacks["take_item_from_box"],
|
|
439
|
-
cb?: ((
|
|
450
|
+
cb?: ((this: void, object: game_object, box: game_object, item: game_object) => void) | null,
|
|
440
451
|
object?: object_binder | null
|
|
441
452
|
): void;
|
|
442
453
|
|
|
@@ -1203,7 +1214,10 @@ declare module "xray16" {
|
|
|
1203
1214
|
public command(entity_action: entity_action, is_high_priority: boolean): void;
|
|
1204
1215
|
public hit(hit: hit): void;
|
|
1205
1216
|
public inactualize_patrol_path(): void;
|
|
1206
|
-
public iterate_inventory(
|
|
1217
|
+
public iterate_inventory(
|
|
1218
|
+
cb: (this: void, owner: game_object, item: game_object) => void,
|
|
1219
|
+
object: game_object
|
|
1220
|
+
): void;
|
|
1207
1221
|
public movement_enabled(): boolean;
|
|
1208
1222
|
public movement_enabled(value: boolean): void;
|
|
1209
1223
|
public set_condition(condition: f32): void;
|
|
@@ -329,6 +329,8 @@ declare module "xray16" {
|
|
|
329
329
|
export class cse_alife_item_weapon_magazined extends cse_alife_item_weapon {}
|
|
330
330
|
|
|
331
331
|
/**
|
|
332
|
+
* Base class for magazined weapons with grenade launcher.
|
|
333
|
+
*
|
|
332
334
|
* @source C++ class cse_alife_item_weapon_magazined_w_gl : cse_alife_item_weapon_magazined
|
|
333
335
|
* @customConstructor cse_alife_item_weapon_magazined_w_gl
|
|
334
336
|
* @group xr_server_object
|
package/plugins/built_at_info.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Program } from "typescript";
|
|
2
|
-
import { Plugin, CompilerOptions, EmitFile, EmitHost } from "typescript-to-lua";
|
|
3
|
-
|
|
4
|
-
const comment: string = `-- Generated by xrf util at: ${new Date().toString()}\n\n`;
|
|
5
|
-
|
|
6
|
-
const plugin: Plugin = {
|
|
7
|
-
beforeEmit(program: Program, options: CompilerOptions, emitHost: EmitHost, result: Array<EmitFile>) {
|
|
8
|
-
void program;
|
|
9
|
-
void options;
|
|
10
|
-
void emitHost;
|
|
11
|
-
|
|
12
|
-
for (const file of result) {
|
|
13
|
-
file.code = comment + file.code;
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default plugin;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { isIdentifier, SyntaxKind } from "typescript";
|
|
2
|
-
import { Plugin } from "typescript-to-lua";
|
|
3
|
-
import { createErrorDiagnosticFactory } from "./utils/diagnostics";
|
|
4
|
-
|
|
5
|
-
const FROM_CAST_METHODS: Array<string> = ["$fromObject", "$fromArray", "$fromLuaArray", "$fromLuaTable"];
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Push generic error to notify about usage issue.
|
|
9
|
-
*/
|
|
10
|
-
const createInvalidFunctionCallError = createErrorDiagnosticFactory((name?: string) => {
|
|
11
|
-
return `Invalid transformer call, expected function to have exactly 1 argument.`;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Plugin for transformation of casting methods.
|
|
16
|
-
* Simplifies TS/Lua testing and interoperation.
|
|
17
|
-
*/
|
|
18
|
-
const plugin: Plugin = {
|
|
19
|
-
visitors: {
|
|
20
|
-
[SyntaxKind.CallExpression]: (node, context) => {
|
|
21
|
-
if (isIdentifier(node.expression) && FROM_CAST_METHODS.includes(node.expression.text)) {
|
|
22
|
-
if (node.arguments.length !== 1) {
|
|
23
|
-
context.diagnostics.push(createInvalidFunctionCallError(node));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return context.transformExpression(node.arguments[0]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return context.superTransformExpression(node);
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default plugin;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { SyntaxKind } from "typescript";
|
|
2
|
-
import { Plugin } from "typescript-to-lua";
|
|
3
|
-
|
|
4
|
-
const XRF_GLOBALS: Array<string> = ["xray16"];
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Plugin that removes imports from 'global' libraries like engine typedefs.
|
|
8
|
-
*/
|
|
9
|
-
const plugin: Plugin = {
|
|
10
|
-
visitors: {
|
|
11
|
-
[SyntaxKind.ImportDeclaration]: (node, context) => {
|
|
12
|
-
const module: string = node.moduleSpecifier.getText().slice(1, -1);
|
|
13
|
-
const shouldNotBeTransformed: boolean = XRF_GLOBALS.includes(module);
|
|
14
|
-
|
|
15
|
-
if (shouldNotBeTransformed) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return context.superTransformStatements(node);
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default plugin;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
import { SyntaxKind } from "typescript";
|
|
3
|
-
import { createStringLiteral, Plugin } from "typescript-to-lua";
|
|
4
|
-
|
|
5
|
-
const FILENAME_IDENTIFIER: string = "$filename";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Plugin that injects FILE_NAME in compile-time.
|
|
9
|
-
*/
|
|
10
|
-
const plugin: Plugin = {
|
|
11
|
-
visitors: {
|
|
12
|
-
[SyntaxKind.Identifier]: (node, context) => {
|
|
13
|
-
if (node.text === FILENAME_IDENTIFIER) {
|
|
14
|
-
return createStringLiteral(path.parse(context.sourceFile.fileName).name);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return context.superTransformExpression(node);
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default plugin;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CallExpression,
|
|
3
|
-
factory,
|
|
4
|
-
Identifier,
|
|
5
|
-
PropertyAccessExpression,
|
|
6
|
-
SyntaxKind,
|
|
7
|
-
Type,
|
|
8
|
-
TypeChecker,
|
|
9
|
-
VariableDeclaration,
|
|
10
|
-
VariableDeclarationList,
|
|
11
|
-
} from "typescript";
|
|
12
|
-
import { Plugin } from "typescript-to-lua";
|
|
13
|
-
|
|
14
|
-
const LUA_LOGGER_STRIP_TARGET: string = "LuaLogger";
|
|
15
|
-
const IS_LUA_LOGGER_DISABLED: boolean = process.argv.includes("--no-lua-logs");
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Plugin that removes all LuaLogger instance creations and calls when possible.
|
|
19
|
-
*/
|
|
20
|
-
const plugin: Plugin = {
|
|
21
|
-
visitors: {
|
|
22
|
-
[SyntaxKind.VariableStatement]: (statement, context) => {
|
|
23
|
-
if (IS_LUA_LOGGER_DISABLED) {
|
|
24
|
-
let elementsCount: number = 0;
|
|
25
|
-
const list = statement.declarationList as VariableDeclarationList;
|
|
26
|
-
const nodes: Array<VariableDeclaration> = [];
|
|
27
|
-
|
|
28
|
-
list.forEachChild((it: VariableDeclaration) => {
|
|
29
|
-
const checker: TypeChecker = context.program.getTypeChecker();
|
|
30
|
-
const typeSymbol: Type = checker.getTypeAtLocation(it);
|
|
31
|
-
|
|
32
|
-
if (typeSymbol.symbol?.name === LUA_LOGGER_STRIP_TARGET) {
|
|
33
|
-
// nothing
|
|
34
|
-
} else {
|
|
35
|
-
nodes.push(it);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
elementsCount += 1;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
if (nodes.length === 0) {
|
|
42
|
-
return undefined;
|
|
43
|
-
} else if (nodes.length !== elementsCount) {
|
|
44
|
-
return context.superTransformStatements(
|
|
45
|
-
factory.createVariableStatement(statement.modifiers, factory.updateVariableDeclarationList(list, nodes))
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return context.superTransformStatements(statement);
|
|
51
|
-
},
|
|
52
|
-
[SyntaxKind.ExpressionStatement]: (statement, context) => {
|
|
53
|
-
if (IS_LUA_LOGGER_DISABLED && statement.expression?.kind === SyntaxKind.CallExpression) {
|
|
54
|
-
const expression: CallExpression = statement.expression as CallExpression;
|
|
55
|
-
const propertyAccess: PropertyAccessExpression = expression.expression as PropertyAccessExpression;
|
|
56
|
-
|
|
57
|
-
if (propertyAccess.expression?.kind === SyntaxKind.Identifier) {
|
|
58
|
-
const checker: TypeChecker = context.program.getTypeChecker();
|
|
59
|
-
const identifier: Identifier = propertyAccess.expression as Identifier;
|
|
60
|
-
const typeSymbol: Type = checker.getTypeAtLocation(identifier);
|
|
61
|
-
|
|
62
|
-
if (typeSymbol.symbol?.name === LUA_LOGGER_STRIP_TARGET) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return context.superTransformStatements(statement);
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export default plugin;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
transformLuabindClassDeclaration,
|
|
3
|
-
transformNewCallExpression,
|
|
4
|
-
isLuabindClassSuperCall,
|
|
5
|
-
transformClassSuperMethodExpression,
|
|
6
|
-
transformLuabindConstructorSuperCall,
|
|
7
|
-
ITransformationContext,
|
|
8
|
-
isLuabindClassType,
|
|
9
|
-
isLuabindDecoratedClass,
|
|
10
|
-
isLuabindClassSuperMethodCall,
|
|
11
|
-
} from "./transformation";
|
|
12
|
-
import { CallExpression, NewExpression, SuperExpression, SyntaxKind } from "typescript";
|
|
13
|
-
import { Plugin } from "typescript-to-lua";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Plugin that transform TS classes marked with decorator to luabind class declaration.
|
|
17
|
-
*/
|
|
18
|
-
const plugin: Plugin = {
|
|
19
|
-
visitors: {
|
|
20
|
-
[SyntaxKind.CallExpression]: (expression: CallExpression, context: ITransformationContext) => {
|
|
21
|
-
if (isLuabindClassSuperCall(expression, context)) {
|
|
22
|
-
return transformLuabindConstructorSuperCall(expression, context);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return context.superTransformExpression(expression);
|
|
26
|
-
},
|
|
27
|
-
[SyntaxKind.ClassDeclaration]: (declaration, context: ITransformationContext) => {
|
|
28
|
-
if (isLuabindDecoratedClass(declaration)) {
|
|
29
|
-
return transformLuabindClassDeclaration(declaration, context);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return context.superTransformStatements(declaration);
|
|
33
|
-
},
|
|
34
|
-
[SyntaxKind.NewExpression]: (expression: NewExpression, context: ITransformationContext) => {
|
|
35
|
-
if (isLuabindClassType(expression, context)) {
|
|
36
|
-
return transformNewCallExpression(expression, context);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return context.superTransformExpression(expression);
|
|
40
|
-
},
|
|
41
|
-
[SyntaxKind.SuperKeyword]: (expression: SuperExpression, context: ITransformationContext) => {
|
|
42
|
-
if (isLuabindClassSuperMethodCall(expression, context)) {
|
|
43
|
-
return transformClassSuperMethodExpression(expression, context);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return context.superTransformExpression(expression);
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default plugin;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { LUABIND_CONSTRUCTOR_METHOD } from "./constants";
|
|
2
|
-
import { checkLuabindClassDecoratorExpression } from "./decorators";
|
|
3
|
-
import { unsupportedStaticMethod } from "./errors";
|
|
4
|
-
import { transformAccessorDeclarations } from "./members/accessors";
|
|
5
|
-
import { createConstructorName, transformConstructorDeclaration } from "./members/constructor";
|
|
6
|
-
import { verifyPropertyDecoratingExpression, transformClassInstanceFields } from "./members/fields";
|
|
7
|
-
import { verifyMethodDecoratingExpression, transformMethodDeclaration } from "./members/method";
|
|
8
|
-
import { createClassSetup } from "./setup";
|
|
9
|
-
import { getExtendedNode, getExtendedType, isStaticNode, markTypeAsLuabind } from "./utils";
|
|
10
|
-
import {
|
|
11
|
-
canHaveDecorators,
|
|
12
|
-
ClassLikeDeclaration,
|
|
13
|
-
ConstructorDeclaration,
|
|
14
|
-
ExpressionWithTypeArguments,
|
|
15
|
-
factory,
|
|
16
|
-
getDecorators,
|
|
17
|
-
isAccessor,
|
|
18
|
-
isConstructorDeclaration,
|
|
19
|
-
isMethodDeclaration,
|
|
20
|
-
isPropertyDeclaration,
|
|
21
|
-
} from "typescript";
|
|
22
|
-
import * as tstl from "typescript-to-lua";
|
|
23
|
-
import { LuaTarget, TransformationContext } from "typescript-to-lua";
|
|
24
|
-
import {
|
|
25
|
-
createDefaultExportExpression,
|
|
26
|
-
createExportedIdentifier,
|
|
27
|
-
hasDefaultExportModifier,
|
|
28
|
-
hasExportModifier,
|
|
29
|
-
} from "typescript-to-lua/dist/transformation/utils/export";
|
|
30
|
-
import { createSelfIdentifier } from "typescript-to-lua/dist/transformation/utils/lua-ast";
|
|
31
|
-
import { transformInPrecedingStatementScope } from "typescript-to-lua/dist/transformation/utils/preceding-statements";
|
|
32
|
-
import { createSafeName, isUnsafeName } from "typescript-to-lua/dist/transformation/utils/safe-names";
|
|
33
|
-
import { transformIdentifier } from "typescript-to-lua/dist/transformation/visitors/identifier";
|
|
34
|
-
|
|
35
|
-
export interface ITransformationContext extends TransformationContext {
|
|
36
|
-
classSuperInfos: Array<ClassSuperInfo>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const transformLuabindClassDeclaration = (declaration, context: TransformationContext) => {
|
|
40
|
-
// If declaration is a default export, transform to export variable assignment instead
|
|
41
|
-
if (hasDefaultExportModifier(declaration)) {
|
|
42
|
-
// Class declaration including assignment to ____exports.default are in preceding statements
|
|
43
|
-
const { precedingStatements } = transformInPrecedingStatementScope(context, () => {
|
|
44
|
-
transformClassAsExpression(declaration, context as ITransformationContext);
|
|
45
|
-
return [];
|
|
46
|
-
});
|
|
47
|
-
return precedingStatements;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { statements } = transformClassLikeDeclaration(declaration, context as ITransformationContext);
|
|
51
|
-
return statements;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export function transformClassAsExpression(
|
|
55
|
-
expression: ClassLikeDeclaration,
|
|
56
|
-
context: ITransformationContext
|
|
57
|
-
): tstl.Expression {
|
|
58
|
-
const { statements, name } = transformClassLikeDeclaration(expression, context);
|
|
59
|
-
context.addPrecedingStatements(statements);
|
|
60
|
-
return name;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** @internal */
|
|
64
|
-
export interface ClassSuperInfo {
|
|
65
|
-
className: tstl.Identifier;
|
|
66
|
-
classDeclaration: ClassLikeDeclaration;
|
|
67
|
-
extendedTypeNode?: ExpressionWithTypeArguments;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function transformClassLikeDeclaration(
|
|
71
|
-
classDeclaration: ClassLikeDeclaration,
|
|
72
|
-
context: ITransformationContext,
|
|
73
|
-
nameOverride?: tstl.Identifier
|
|
74
|
-
): { statements: tstl.Statement[]; name: tstl.Identifier } {
|
|
75
|
-
let className: tstl.Identifier;
|
|
76
|
-
|
|
77
|
-
if (nameOverride !== undefined) {
|
|
78
|
-
className = nameOverride;
|
|
79
|
-
} else if (classDeclaration.name !== undefined) {
|
|
80
|
-
className = transformIdentifier(context, classDeclaration.name);
|
|
81
|
-
} else {
|
|
82
|
-
className = tstl.createIdentifier(context.createTempName("class"), classDeclaration);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
markTypeAsLuabind(classDeclaration, context);
|
|
86
|
-
|
|
87
|
-
// Get type that is extended
|
|
88
|
-
const extendedTypeNode = getExtendedNode(classDeclaration);
|
|
89
|
-
const extendedType = getExtendedType(context, classDeclaration);
|
|
90
|
-
|
|
91
|
-
context.classSuperInfos.push({ className, classDeclaration: classDeclaration, extendedTypeNode });
|
|
92
|
-
|
|
93
|
-
// Get all properties with value
|
|
94
|
-
const properties = classDeclaration.members.filter(isPropertyDeclaration).filter((member) => member.initializer);
|
|
95
|
-
|
|
96
|
-
// Divide properties into static and non-static
|
|
97
|
-
const instanceFields = properties.filter((prop) => !isStaticNode(prop));
|
|
98
|
-
|
|
99
|
-
const result: tstl.Statement[] = [];
|
|
100
|
-
|
|
101
|
-
let localClassName: tstl.Identifier;
|
|
102
|
-
if (isUnsafeName(className.text, context.options)) {
|
|
103
|
-
localClassName = tstl.createIdentifier(
|
|
104
|
-
createSafeName(className.text),
|
|
105
|
-
undefined,
|
|
106
|
-
className.symbolId,
|
|
107
|
-
className.text
|
|
108
|
-
);
|
|
109
|
-
tstl.setNodePosition(localClassName, className);
|
|
110
|
-
} else {
|
|
111
|
-
localClassName = className;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
result.push(...createClassSetup(context, classDeclaration, className, localClassName));
|
|
115
|
-
|
|
116
|
-
// Find first constructor with body
|
|
117
|
-
const constructor = classDeclaration.members.find(
|
|
118
|
-
(n): n is ConstructorDeclaration => isConstructorDeclaration(n) && n.body !== undefined
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
if (constructor) {
|
|
122
|
-
// Add constructor plus initialization of instance fields
|
|
123
|
-
const constructorResult = transformConstructorDeclaration(
|
|
124
|
-
context,
|
|
125
|
-
constructor,
|
|
126
|
-
localClassName,
|
|
127
|
-
instanceFields,
|
|
128
|
-
classDeclaration
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
if (constructorResult) result.push(constructorResult);
|
|
132
|
-
} else if (!extendedType) {
|
|
133
|
-
// Generate a constructor if none was defined in a base class
|
|
134
|
-
const constructorResult = transformConstructorDeclaration(
|
|
135
|
-
context,
|
|
136
|
-
factory.createConstructorDeclaration([], [], factory.createBlock([], true)),
|
|
137
|
-
localClassName,
|
|
138
|
-
instanceFields,
|
|
139
|
-
classDeclaration
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
if (constructorResult) result.push(constructorResult);
|
|
143
|
-
} else {
|
|
144
|
-
// Generate a constructor if none was defined in a class with instance fields that need initialization
|
|
145
|
-
// localClassName.__init = function(self, ...)
|
|
146
|
-
// baseClassName.__init(self, ...) // or unpack(arg) for Lua 5.0
|
|
147
|
-
// ...
|
|
148
|
-
// Also luabind always needs definition of call expression to use table as class.
|
|
149
|
-
const constructorBody = transformClassInstanceFields(context, instanceFields);
|
|
150
|
-
const argsExpression =
|
|
151
|
-
context.luaTarget === LuaTarget.Lua50
|
|
152
|
-
? tstl.createCallExpression(tstl.createIdentifier("unpack"), [tstl.createArgLiteral()])
|
|
153
|
-
: tstl.createDotsLiteral();
|
|
154
|
-
const superCall = tstl.createExpressionStatement(
|
|
155
|
-
tstl.createCallExpression(
|
|
156
|
-
tstl.createTableIndexExpression(
|
|
157
|
-
context.transformExpression(factory.createSuper()),
|
|
158
|
-
tstl.createStringLiteral(LUABIND_CONSTRUCTOR_METHOD)
|
|
159
|
-
),
|
|
160
|
-
[createSelfIdentifier(), argsExpression]
|
|
161
|
-
)
|
|
162
|
-
);
|
|
163
|
-
constructorBody.unshift(superCall);
|
|
164
|
-
const constructorFunction = tstl.createFunctionExpression(
|
|
165
|
-
tstl.createBlock(constructorBody),
|
|
166
|
-
[createSelfIdentifier()],
|
|
167
|
-
tstl.createDotsLiteral(),
|
|
168
|
-
tstl.NodeFlags.Declaration
|
|
169
|
-
);
|
|
170
|
-
result.push(
|
|
171
|
-
tstl.createAssignmentStatement(createConstructorName(localClassName), constructorFunction, classDeclaration)
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Transform accessors
|
|
176
|
-
for (const member of classDeclaration.members) {
|
|
177
|
-
if (!isAccessor(member)) continue;
|
|
178
|
-
const accessors = context.resolver.getAllAccessorDeclarations(member);
|
|
179
|
-
if (accessors.firstAccessor !== member) continue;
|
|
180
|
-
|
|
181
|
-
const accessorsResult = transformAccessorDeclarations(context, accessors, localClassName);
|
|
182
|
-
if (accessorsResult) {
|
|
183
|
-
result.push(accessorsResult);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const decorationStatements: tstl.Statement[] = [];
|
|
188
|
-
|
|
189
|
-
for (const member of classDeclaration.members) {
|
|
190
|
-
if (isAccessor(member)) {
|
|
191
|
-
verifyPropertyDecoratingExpression(context, member);
|
|
192
|
-
} else if (isMethodDeclaration(member)) {
|
|
193
|
-
const statement = transformMethodDeclaration(context, member, localClassName);
|
|
194
|
-
if (statement) result.push(statement);
|
|
195
|
-
if (member.body) {
|
|
196
|
-
verifyMethodDecoratingExpression(context, member);
|
|
197
|
-
}
|
|
198
|
-
} else if (isPropertyDeclaration(member)) {
|
|
199
|
-
if (isStaticNode(member)) {
|
|
200
|
-
context.diagnostics.push(unsupportedStaticMethod(member));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
verifyPropertyDecoratingExpression(context, member);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
result.push(...decorationStatements);
|
|
208
|
-
|
|
209
|
-
// Decorate the class
|
|
210
|
-
if (canHaveDecorators(classDeclaration) && getDecorators(classDeclaration)) {
|
|
211
|
-
getDecorators(classDeclaration)?.forEach((d) => checkLuabindClassDecoratorExpression(context, d));
|
|
212
|
-
|
|
213
|
-
if (hasExportModifier(classDeclaration)) {
|
|
214
|
-
const exportExpression = hasDefaultExportModifier(classDeclaration)
|
|
215
|
-
? createDefaultExportExpression(classDeclaration)
|
|
216
|
-
: createExportedIdentifier(context, className);
|
|
217
|
-
|
|
218
|
-
const classAssignment = tstl.createAssignmentStatement(exportExpression, localClassName);
|
|
219
|
-
result.push(classAssignment);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
context.classSuperInfos.pop();
|
|
224
|
-
|
|
225
|
-
return { statements: result, name: className };
|
|
226
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { unsupportedClassDecorator } from "./errors";
|
|
2
|
-
import { LUABIND_DECORATOR } from "./constants";
|
|
3
|
-
import { CallExpression, Decorator, Identifier } from "typescript";
|
|
4
|
-
import { TransformationContext } from "typescript-to-lua";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Transform decorator call expressions for luabind class.
|
|
8
|
-
*/
|
|
9
|
-
export function checkLuabindClassDecoratorExpression(context: TransformationContext, decorator: Decorator) {
|
|
10
|
-
const expression = decorator.expression;
|
|
11
|
-
|
|
12
|
-
// Do not transform luabind decorator.
|
|
13
|
-
if (((expression as CallExpression).expression as Identifier).text !== LUABIND_DECORATOR) {
|
|
14
|
-
context.diagnostics.push(unsupportedClassDecorator(expression));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createErrorDiagnosticFactory } from "../../utils/diagnostics";
|
|
2
|
-
|
|
3
|
-
export const unsupportedStaticMethod = createErrorDiagnosticFactory((name?: string) => {
|
|
4
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
5
|
-
return `Unable transform static properties for luabind classes${nameReference}.`;
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export const unsupportedClassDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
9
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
10
|
-
return `Unable transform class decorators for luabind classes${nameReference}.`;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const unsupportedPropertyDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
14
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
15
|
-
return `Unable transform property decorator for luabind classes${nameReference}.`;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export const unsupportedParameterDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
19
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
20
|
-
return `Unable transform parameter decorator for luabind classes${nameReference}.`;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const unsupportedMethodDecorator = createErrorDiagnosticFactory((name?: string) => {
|
|
24
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
25
|
-
return `Unable transform method decorator for luabind classes${nameReference}.`;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export const unsupportedStaticAccessor = createErrorDiagnosticFactory((name?: string) => {
|
|
29
|
-
const nameReference = name ? ` '${name}'` : "";
|
|
30
|
-
return `Unable transform static accessors for luabind classes${nameReference}.`;
|
|
31
|
-
});
|