xray16 1.0.0 → 1.0.1

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.
Files changed (97) hide show
  1. package/README.md +29 -0
  2. package/package.json +7 -4
  3. package/plugins/built_at_info.js +14 -0
  4. package/plugins/from_cast_utils.js +29 -0
  5. package/plugins/global_declarations_transform.js +20 -0
  6. package/plugins/inject_filename.js +20 -0
  7. package/plugins/plugins/built_at_info.js +12 -0
  8. package/plugins/plugins/from_cast_utils.js +27 -0
  9. package/plugins/plugins/global_declarations_transform.js +18 -0
  10. package/plugins/plugins/inject_filename.js +18 -0
  11. package/plugins/plugins/strip_lua_logger.js +51 -0
  12. package/plugins/plugins/transform_luabind_class/plugin.js +34 -0
  13. package/plugins/plugins/transform_luabind_class/transformation/class_declaration.js +141 -0
  14. package/plugins/plugins/transform_luabind_class/transformation/constants.js +4 -0
  15. package/plugins/plugins/transform_luabind_class/transformation/decorators.js +12 -0
  16. package/plugins/plugins/transform_luabind_class/transformation/errors.js +25 -0
  17. package/plugins/{transform_luabind_class/transformation/index.ts → plugins/transform_luabind_class/transformation/index.js} +5 -5
  18. package/plugins/plugins/transform_luabind_class/transformation/members/accessors.js +35 -0
  19. package/plugins/plugins/transform_luabind_class/transformation/members/constructor.js +56 -0
  20. package/plugins/plugins/transform_luabind_class/transformation/members/fields.js +36 -0
  21. package/plugins/plugins/transform_luabind_class/transformation/members/method.js +49 -0
  22. package/plugins/plugins/transform_luabind_class/transformation/new.js +8 -0
  23. package/plugins/plugins/transform_luabind_class/transformation/setup.js +76 -0
  24. package/plugins/plugins/transform_luabind_class/transformation/super.js +65 -0
  25. package/plugins/plugins/transform_luabind_class/transformation/utils.js +67 -0
  26. package/plugins/plugins/utils/diagnostics.js +17 -0
  27. package/plugins/strip_lua_logger.js +53 -0
  28. package/plugins/transform_luabind_class/plugin.js +36 -0
  29. package/plugins/transform_luabind_class/transformation/class_declaration.js +147 -0
  30. package/plugins/transform_luabind_class/transformation/constants.js +7 -0
  31. package/plugins/transform_luabind_class/transformation/decorators.js +16 -0
  32. package/plugins/transform_luabind_class/transformation/errors.js +28 -0
  33. package/plugins/transform_luabind_class/transformation/index.js +21 -0
  34. package/plugins/transform_luabind_class/transformation/members/accessors.js +39 -0
  35. package/plugins/transform_luabind_class/transformation/members/constructor.js +61 -0
  36. package/plugins/transform_luabind_class/transformation/members/fields.js +41 -0
  37. package/plugins/transform_luabind_class/transformation/members/method.js +56 -0
  38. package/plugins/transform_luabind_class/transformation/new.js +12 -0
  39. package/plugins/transform_luabind_class/transformation/setup.js +81 -0
  40. package/plugins/transform_luabind_class/transformation/super.js +72 -0
  41. package/plugins/transform_luabind_class/transformation/utils.js +77 -0
  42. package/plugins/utils/diagnostics.js +22 -0
  43. package/types/index.d.ts +63 -0
  44. package/{src → types}/xr_object/xr_client_object.d.ts +4 -1
  45. package/plugins/built_at_info.ts +0 -18
  46. package/plugins/from_cast_utils.ts +0 -34
  47. package/plugins/global_declarations_transform.ts +0 -24
  48. package/plugins/inject_filename.ts +0 -22
  49. package/plugins/strip_lua_logger.ts +0 -73
  50. package/plugins/transform_luabind_class/plugin.ts +0 -51
  51. package/plugins/transform_luabind_class/transformation/class_declaration.ts +0 -226
  52. package/plugins/transform_luabind_class/transformation/constants.ts +0 -4
  53. package/plugins/transform_luabind_class/transformation/decorators.ts +0 -16
  54. package/plugins/transform_luabind_class/transformation/errors.ts +0 -31
  55. package/plugins/transform_luabind_class/transformation/members/accessors.ts +0 -48
  56. package/plugins/transform_luabind_class/transformation/members/constructor.ts +0 -107
  57. package/plugins/transform_luabind_class/transformation/members/fields.ts +0 -53
  58. package/plugins/transform_luabind_class/transformation/members/method.ts +0 -70
  59. package/plugins/transform_luabind_class/transformation/new.ts +0 -14
  60. package/plugins/transform_luabind_class/transformation/setup.ts +0 -128
  61. package/plugins/transform_luabind_class/transformation/super.ts +0 -92
  62. package/plugins/transform_luabind_class/transformation/utils.ts +0 -90
  63. package/plugins/utils/diagnostics.ts +0 -24
  64. package/src/index.d.ts +0 -63
  65. /package/{src → types}/xr_constant.d.ts +0 -0
  66. /package/{src → types}/xr_core.d.ts +0 -0
  67. /package/{src → types}/xr_global.d.ts +0 -0
  68. /package/{src → types}/xr_lib/xr_fs.d.ts +0 -0
  69. /package/{src → types}/xr_lib/xr_math.d.ts +0 -0
  70. /package/{src → types}/xr_lib/xr_utils.d.ts +0 -0
  71. /package/{src → types}/xr_luabind.d.ts +0 -0
  72. /package/{src → types}/xr_map/xr_map.d.ts +0 -0
  73. /package/{src → types}/xr_object/xr_action.d.ts +0 -0
  74. /package/{src → types}/xr_object/xr_alife.d.ts +0 -0
  75. /package/{src → types}/xr_object/xr_anomaly.d.ts +0 -0
  76. /package/{src → types}/xr_object/xr_artefact.d.ts +0 -0
  77. /package/{src → types}/xr_object/xr_creature.d.ts +0 -0
  78. /package/{src → types}/xr_object/xr_dialog.d.ts +0 -0
  79. /package/{src → types}/xr_object/xr_item.d.ts +0 -0
  80. /package/{src → types}/xr_object/xr_level.d.ts +0 -0
  81. /package/{src → types}/xr_object/xr_physic.d.ts +0 -0
  82. /package/{src → types}/xr_object/xr_quest.d.ts +0 -0
  83. /package/{src → types}/xr_object/xr_server_object.d.ts +0 -0
  84. /package/{src → types}/xr_online/xr_multiplayer.d.ts +0 -0
  85. /package/{src → types}/xr_sound/xr_sound.d.ts +0 -0
  86. /package/{src → types}/xr_type/xr_enums.d.ts +0 -0
  87. /package/{src → types}/xr_type/xr_type.d.ts +0 -0
  88. /package/{src → types}/xr_ui/README.md +0 -0
  89. /package/{src → types}/xr_ui/demo/CServerList.png +0 -0
  90. /package/{src → types}/xr_ui/demo/CUI3tButton.png +0 -0
  91. /package/{src → types}/xr_ui/demo/CUICheckButton.png +0 -0
  92. /package/{src → types}/xr_ui/demo/CUIComboBox.png +0 -0
  93. /package/{src → types}/xr_ui/demo/CUICustomEdit.png +0 -0
  94. /package/{src → types}/xr_ui/demo/CUIStatic.png +0 -0
  95. /package/{src → types}/xr_ui/demo/CUITrackBar.png +0 -0
  96. /package/{src → types}/xr_ui/xr_ui_core.d.ts +0 -0
  97. /package/{src → types}/xr_ui/xr_ui_interface.d.ts +0 -0
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformConstructorDeclaration = exports.createConstructorName = void 0;
4
+ const typescript_1 = require("typescript");
5
+ const lua = require("typescript-to-lua");
6
+ const lua_ast_1 = require("typescript-to-lua/dist/transformation/utils/lua-ast");
7
+ const scope_1 = require("typescript-to-lua/dist/transformation/utils/scope");
8
+ const function_1 = require("typescript-to-lua/dist/transformation/visitors/function");
9
+ const identifier_1 = require("typescript-to-lua/dist/transformation/visitors/identifier");
10
+ const constants_1 = require("../constants");
11
+ const fields_1 = require("./fields");
12
+ function createConstructorName(className) {
13
+ return lua.createTableIndexExpression(lua.cloneIdentifier(className), lua.createStringLiteral(constants_1.LUABIND_CONSTRUCTOR_METHOD));
14
+ }
15
+ exports.createConstructorName = createConstructorName;
16
+ function transformConstructorDeclaration(context, statement, className, instanceFields, classDeclaration) {
17
+ // Don't transform methods without body (overload declarations)
18
+ if (!statement.body) {
19
+ return undefined;
20
+ }
21
+ // Transform body
22
+ const scope = context.pushScope(scope_1.ScopeType.Function);
23
+ const body = (0, function_1.transformFunctionBodyContent)(context, statement.body);
24
+ const [params, dotsLiteral, restParamName] = (0, function_1.transformParameters)(context, statement.parameters, (0, lua_ast_1.createSelfIdentifier)());
25
+ // Make sure default parameters are assigned before fields are initialized
26
+ const bodyWithFieldInitializers = (0, function_1.transformFunctionBodyHeader)(context, scope, statement.parameters, restParamName);
27
+ // Check for field declarations in constructor
28
+ const constructorFieldsDeclarations = statement.parameters.filter((p) => p.modifiers !== undefined);
29
+ const classInstanceFields = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
30
+ // If there are field initializers and the first statement is a super call,
31
+ // move super call between default assignments and initializers
32
+ if ((constructorFieldsDeclarations.length > 0 || classInstanceFields.length > 0) &&
33
+ statement.body &&
34
+ statement.body.statements.length > 0) {
35
+ const firstStatement = statement.body.statements[0];
36
+ if ((0, typescript_1.isExpressionStatement)(firstStatement) &&
37
+ (0, typescript_1.isCallExpression)(firstStatement.expression) &&
38
+ firstStatement.expression.expression.kind === typescript_1.SyntaxKind.SuperKeyword) {
39
+ const superCall = body.shift();
40
+ if (superCall) {
41
+ bodyWithFieldInitializers.push(superCall);
42
+ }
43
+ }
44
+ }
45
+ // Add in instance field declarations
46
+ for (const declaration of constructorFieldsDeclarations) {
47
+ if ((0, typescript_1.isIdentifier)(declaration.name)) {
48
+ // self.declarationName = declarationName
49
+ const assignment = lua.createAssignmentStatement(lua.createTableIndexExpression((0, lua_ast_1.createSelfIdentifier)(), lua.createStringLiteral(declaration.name.text)), (0, identifier_1.transformIdentifier)(context, declaration.name));
50
+ bodyWithFieldInitializers.push(assignment);
51
+ }
52
+ // else { TypeScript error: A parameter property may not be declared using a binding pattern }
53
+ }
54
+ bodyWithFieldInitializers.push(...classInstanceFields);
55
+ bodyWithFieldInitializers.push(...body);
56
+ const block = lua.createBlock(bodyWithFieldInitializers);
57
+ const constructorWasGenerated = statement.pos === -1;
58
+ context.popScope();
59
+ return lua.createAssignmentStatement(createConstructorName(className), lua.createFunctionExpression(block, params, dotsLiteral, lua.NodeFlags.Declaration), constructorWasGenerated ? classDeclaration : statement);
60
+ }
61
+ exports.transformConstructorDeclaration = transformConstructorDeclaration;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformClassInstanceFields = exports.verifyPropertyDecoratingExpression = void 0;
4
+ const typescript_1 = require("typescript");
5
+ const tstl = require("typescript-to-lua");
6
+ const lua_ast_1 = require("typescript-to-lua/dist/transformation/utils/lua-ast");
7
+ const preceding_statements_1 = require("typescript-to-lua/dist/transformation/utils/preceding-statements");
8
+ const literal_1 = require("typescript-to-lua/dist/transformation/visitors/literal");
9
+ const errors_1 = require("../errors");
10
+ /**
11
+ * Verify whether decorators provided for luabind class.
12
+ */
13
+ function verifyPropertyDecoratingExpression(context, node) {
14
+ if (!(0, typescript_1.canHaveDecorators)(node))
15
+ return;
16
+ const decorators = (0, typescript_1.getDecorators)(node);
17
+ if (!decorators)
18
+ return;
19
+ decorators.forEach((decorator) => {
20
+ context.diagnostics.push((0, errors_1.unsupportedPropertyDecorator)(decorator));
21
+ });
22
+ }
23
+ exports.verifyPropertyDecoratingExpression = verifyPropertyDecoratingExpression;
24
+ function transformClassInstanceFields(context, instanceFields) {
25
+ const statements = [];
26
+ for (const f of instanceFields) {
27
+ const { precedingStatements, result: statement } = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => {
28
+ // Get identifier
29
+ const fieldName = (0, literal_1.transformPropertyName)(context, f.name);
30
+ const value = f.initializer ? context.transformExpression(f.initializer) : undefined;
31
+ // self[fieldName]
32
+ const selfIndex = tstl.createTableIndexExpression((0, lua_ast_1.createSelfIdentifier)(), fieldName);
33
+ // self[fieldName] = value
34
+ const assignClassField = tstl.createAssignmentStatement(selfIndex, value, f);
35
+ return assignClassField;
36
+ });
37
+ statements.push(...precedingStatements, statement);
38
+ }
39
+ return statements;
40
+ }
41
+ exports.transformClassInstanceFields = transformClassInstanceFields;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyMethodDecoratingExpression = exports.transformMethodDeclaration = exports.transformMethodName = exports.transformMemberExpressionOwnerName = void 0;
4
+ const typescript_1 = require("typescript");
5
+ const lua = require("typescript-to-lua");
6
+ const function_1 = require("typescript-to-lua/dist/transformation/visitors/function");
7
+ const literal_1 = require("typescript-to-lua/dist/transformation/visitors/literal");
8
+ const errors_1 = require("../errors");
9
+ const utils_1 = require("../utils");
10
+ function transformMemberExpressionOwnerName(node, className) {
11
+ return lua.cloneIdentifier(className);
12
+ }
13
+ exports.transformMemberExpressionOwnerName = transformMemberExpressionOwnerName;
14
+ function transformMethodName(context, node) {
15
+ const methodName = (0, literal_1.transformPropertyName)(context, node.name);
16
+ if (lua.isStringLiteral(methodName) && methodName.value === "toString") {
17
+ return lua.createStringLiteral("__tostring", node.name);
18
+ }
19
+ return methodName;
20
+ }
21
+ exports.transformMethodName = transformMethodName;
22
+ function transformMethodDeclaration(context, node, className) {
23
+ // Don't transform methods without body (overload declarations)
24
+ if (!node.body)
25
+ return;
26
+ // Don't transform static methods for luabind classes.
27
+ if ((0, utils_1.isStaticNode)(node)) {
28
+ context.diagnostics.push((0, errors_1.unsupportedStaticMethod)(node));
29
+ return;
30
+ }
31
+ const methodTable = transformMemberExpressionOwnerName(node, className);
32
+ const methodName = transformMethodName(context, node);
33
+ const [functionExpression] = (0, function_1.transformFunctionToExpression)(context, node);
34
+ return lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), functionExpression, node);
35
+ }
36
+ exports.transformMethodDeclaration = transformMethodDeclaration;
37
+ /**
38
+ * Verify that method statement is not using decorators for methods/parameters.
39
+ */
40
+ function verifyMethodDecoratingExpression(context, node) {
41
+ node.parameters.flatMap((parameter, index) => {
42
+ const decorators = (0, typescript_1.getDecorators)(parameter);
43
+ if (decorators?.length) {
44
+ decorators.forEach((decorator) => {
45
+ context.diagnostics.push((0, errors_1.unsupportedParameterDecorator)(decorator));
46
+ });
47
+ }
48
+ });
49
+ const decorators = (0, typescript_1.getDecorators)(node);
50
+ if (decorators?.length) {
51
+ decorators.forEach((decorator) => {
52
+ context.diagnostics.push((0, errors_1.unsupportedMethodDecorator)(decorator));
53
+ });
54
+ }
55
+ }
56
+ exports.verifyMethodDecoratingExpression = verifyMethodDecoratingExpression;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformNewCallExpression = void 0;
4
+ const tstl = require("typescript-to-lua");
5
+ const call_1 = require("typescript-to-lua/dist/transformation/visitors/call");
6
+ /**
7
+ * Transform new call for luabind class as ClassConstructor() instead of TS_NEW from tstl.
8
+ */
9
+ function transformNewCallExpression(expression, context) {
10
+ return tstl.createCallExpression(context.transformExpression(expression.expression), (0, call_1.transformArguments)(context, expression.arguments ?? []));
11
+ }
12
+ exports.transformNewCallExpression = transformNewCallExpression;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getReflectionClassName = exports.createClassSetup = void 0;
4
+ const typescript_1 = require("typescript");
5
+ const tstl = require("typescript-to-lua");
6
+ const export_1 = require("typescript-to-lua/dist/transformation/utils/export");
7
+ const lua_ast_1 = require("typescript-to-lua/dist/transformation/utils/lua-ast");
8
+ const constants_1 = require("./constants");
9
+ const utils_1 = require("./utils");
10
+ /**
11
+ * Create full class setup statement with name/super calls/methods/declaration/fields etc.
12
+ */
13
+ function createClassSetup(context, statement, className, localClassName) {
14
+ const result = [];
15
+ // class("name")(base)
16
+ const classInitializer = createLuabindClassStatement(statement, context, localClassName);
17
+ result.push(tstl.createExpressionStatement(classInitializer));
18
+ const classReference = createLuabindClassGlobalClassRef(statement, context, localClassName);
19
+ const defaultExportLeftHandSide = (0, export_1.hasDefaultExportModifier)(statement)
20
+ ? tstl.createTableIndexExpression((0, lua_ast_1.createExportsIdentifier)(), (0, export_1.createDefaultExportStringLiteral)(statement))
21
+ : undefined;
22
+ // [____exports.]className = class()
23
+ if (defaultExportLeftHandSide) {
24
+ result.push(tstl.createAssignmentStatement(defaultExportLeftHandSide, classReference, statement));
25
+ }
26
+ else {
27
+ result.push(...(0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, className, classReference, statement));
28
+ }
29
+ if (defaultExportLeftHandSide) {
30
+ // local localClassName = ____exports.default
31
+ result.push(tstl.createVariableDeclarationStatement(localClassName, defaultExportLeftHandSide));
32
+ }
33
+ else {
34
+ const exportScope = (0, export_1.getIdentifierExportScope)(context, className);
35
+ if (exportScope) {
36
+ // local localClassName = ____exports.className
37
+ result.push(tstl.createVariableDeclarationStatement(localClassName, (0, export_1.createExportedIdentifier)(context, tstl.cloneIdentifier(className), exportScope)));
38
+ }
39
+ }
40
+ // localClassName.__name = className
41
+ result.push(tstl.createAssignmentStatement(tstl.createTableIndexExpression(tstl.cloneIdentifier(localClassName), tstl.createStringLiteral(constants_1.LUABIND_NAME_FIELD)), getReflectionClassName(statement, className), statement));
42
+ return result;
43
+ }
44
+ exports.createClassSetup = createClassSetup;
45
+ function getReflectionClassName(declaration, className) {
46
+ if (declaration.name) {
47
+ return tstl.createStringLiteral(declaration.name.text);
48
+ }
49
+ else if ((0, typescript_1.isVariableDeclaration)(declaration.parent) && (0, typescript_1.isIdentifier)(declaration.parent.name)) {
50
+ return tstl.createStringLiteral(declaration.parent.name.text);
51
+ }
52
+ else if ((0, export_1.hasDefaultExportModifier)(declaration)) {
53
+ return tstl.createStringLiteral("default");
54
+ }
55
+ if ((0, utils_1.getExtendedNode)(declaration)) {
56
+ return tstl.createTableIndexExpression(className, tstl.createStringLiteral("name"));
57
+ }
58
+ return tstl.createStringLiteral("");
59
+ }
60
+ exports.getReflectionClassName = getReflectionClassName;
61
+ /**
62
+ * Creates class("Name")(base) expression for luabind classes.
63
+ */
64
+ function createLuabindClassStatement(declaration, context, className) {
65
+ const extendedNode = (0, utils_1.getExtendedNode)(declaration);
66
+ let classDeclaration = tstl.createCallExpression(tstl.createIdentifier("class"), [
67
+ getReflectionClassName(declaration, className),
68
+ ]);
69
+ if (extendedNode) {
70
+ classDeclaration = tstl.createCallExpression(classDeclaration, [
71
+ context.transformExpression(extendedNode.expression),
72
+ ]);
73
+ }
74
+ return classDeclaration;
75
+ }
76
+ /**
77
+ * Creates name expression for luabind classes.
78
+ */
79
+ function createLuabindClassGlobalClassRef(declaration, context, className) {
80
+ return className;
81
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformLuabindConstructorSuperCall = exports.isLuabindClassSuperMethodCall = exports.isLuabindClassSuperCall = exports.transformClassSuperMethodExpression = void 0;
4
+ const typescript_1 = require("typescript");
5
+ const tstl = require("typescript-to-lua");
6
+ const export_1 = require("typescript-to-lua/dist/transformation/utils/export");
7
+ const call_1 = require("typescript-to-lua/dist/transformation/visitors/call");
8
+ const identifier_1 = require("typescript-to-lua/dist/transformation/visitors/identifier");
9
+ const constants_1 = require("./constants");
10
+ const utils_1 = require("./utils");
11
+ /**
12
+ * Transform generic methods super calls.
13
+ * Example: super.parentMethod(first, second).
14
+ */
15
+ function transformClassSuperMethodExpression(expression, context) {
16
+ const superInfos = context.classSuperInfos;
17
+ const superInfo = superInfos[superInfos.length - 1];
18
+ if (!superInfo.classDeclaration || !(0, utils_1.isLuabindClassType)(superInfo.classDeclaration, context)) {
19
+ return context.superTransformExpression(expression);
20
+ }
21
+ const { extendedTypeNode } = superInfo;
22
+ // Using `super` without extended type node is a TypeScript error
23
+ const extendsExpression = extendedTypeNode?.expression;
24
+ let baseClassName;
25
+ if (extendsExpression && (0, typescript_1.isIdentifier)(extendsExpression)) {
26
+ const symbol = context.checker.getSymbolAtLocation(extendsExpression);
27
+ if (symbol && !(0, export_1.isSymbolExported)(context, symbol)) {
28
+ // Use "baseClassName" if base is a simple identifier
29
+ baseClassName = (0, identifier_1.transformIdentifier)(context, extendsExpression);
30
+ }
31
+ }
32
+ if (!baseClassName) {
33
+ throw new Error("Super without identifier - not supported with luabind.");
34
+ }
35
+ return baseClassName;
36
+ }
37
+ exports.transformClassSuperMethodExpression = transformClassSuperMethodExpression;
38
+ /**
39
+ * Check if super() call is in luabind class target.
40
+ */
41
+ function isLuabindClassSuperCall(expression, context) {
42
+ const calledExpression = (0, call_1.getCalledExpression)(expression);
43
+ if (calledExpression.kind !== typescript_1.SyntaxKind.SuperKeyword) {
44
+ return false;
45
+ }
46
+ else {
47
+ const superInfos = context.classSuperInfos;
48
+ const superInfo = superInfos[superInfos.length - 1];
49
+ // Handle super calls properly for luabind classes.
50
+ return superInfo?.classDeclaration ? (0, utils_1.isLuabindClassType)(superInfo.classDeclaration, context) : false;
51
+ }
52
+ }
53
+ exports.isLuabindClassSuperCall = isLuabindClassSuperCall;
54
+ /**
55
+ * Check if super.method() call is in luabind class target.
56
+ */
57
+ function isLuabindClassSuperMethodCall(expression, context) {
58
+ const superInfos = context.classSuperInfos;
59
+ const superInfo = superInfos[superInfos.length - 1];
60
+ // Handle super calls properly for luabind classes.
61
+ return superInfo?.classDeclaration ? (0, utils_1.isLuabindClassType)(superInfo.classDeclaration, context) : false;
62
+ }
63
+ exports.isLuabindClassSuperMethodCall = isLuabindClassSuperMethodCall;
64
+ /**
65
+ * Transform super() call in luabind classes to base_class.__init(self, param).
66
+ */
67
+ function transformLuabindConstructorSuperCall(expression, context) {
68
+ const signature = context.checker.getResolvedSignature(expression);
69
+ const parameters = (0, call_1.transformArguments)(context, expression.arguments, signature, typescript_1.factory.createThis());
70
+ return tstl.createCallExpression(tstl.createTableIndexExpression(context.transformExpression(typescript_1.factory.createSuper()), tstl.createStringLiteral(constants_1.LUABIND_CONSTRUCTOR_METHOD)), parameters, expression);
71
+ }
72
+ exports.transformLuabindConstructorSuperCall = transformLuabindConstructorSuperCall;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLuabindClassType = exports.markTypeAsLuabind = exports.isLuabindDecoratedClass = exports.getExtendedType = exports.getExtendedNode = exports.getExtendsClause = exports.isStaticNode = void 0;
4
+ const typescript_1 = require("typescript");
5
+ const constants_1 = require("./constants");
6
+ /**
7
+ * Whether method / field is static.
8
+ */
9
+ function isStaticNode(node) {
10
+ return node.modifiers?.some((m) => m.kind === typescript_1.SyntaxKind.StaticKeyword) === true;
11
+ }
12
+ exports.isStaticNode = isStaticNode;
13
+ /**
14
+ * Get class extends node.
15
+ */
16
+ function getExtendsClause(node) {
17
+ return node.heritageClauses?.find((clause) => clause.token === typescript_1.SyntaxKind.ExtendsKeyword);
18
+ }
19
+ exports.getExtendsClause = getExtendsClause;
20
+ /**
21
+ * Get class extended node.
22
+ */
23
+ function getExtendedNode(node) {
24
+ const extendsClause = getExtendsClause(node);
25
+ if (!extendsClause)
26
+ return;
27
+ return extendsClause.types[0];
28
+ }
29
+ exports.getExtendedNode = getExtendedNode;
30
+ /**
31
+ * Get class extended node.
32
+ */
33
+ function getExtendedType(context, node) {
34
+ const extendedNode = getExtendedNode(node);
35
+ return extendedNode && context.checker.getTypeAtLocation(extendedNode);
36
+ }
37
+ exports.getExtendedType = getExtendedType;
38
+ /**
39
+ * Check if class is decorated with provided decorator name.
40
+ */
41
+ function isLuabindDecoratedClass(declaration) {
42
+ const decorators = (0, typescript_1.getDecorators)(declaration);
43
+ if (!decorators) {
44
+ return false;
45
+ }
46
+ return decorators.some((it) => it.expression.expression?.escapedText === constants_1.LUABIND_DECORATOR);
47
+ }
48
+ exports.isLuabindDecoratedClass = isLuabindDecoratedClass;
49
+ /**
50
+ * Mark provided class as Luabind target.
51
+ */
52
+ function markTypeAsLuabind(declaration, context) {
53
+ const typeAtLocation = context.checker.getTypeAtLocation(declaration);
54
+ const typeSymbol = typeAtLocation.symbol || typeAtLocation.aliasSymbol;
55
+ typeSymbol[constants_1.LUABIND_SYMBOL] = true;
56
+ }
57
+ exports.markTypeAsLuabind = markTypeAsLuabind;
58
+ /**
59
+ * Check if provided class is specified as LuaBind.
60
+ */
61
+ function isLuabindClassType(declaration, context) {
62
+ const typeAtLocation = context.checker.getTypeAtLocation(declaration);
63
+ const typeSymbol = typeAtLocation.symbol || typeAtLocation.aliasSymbol;
64
+ if (typeSymbol) {
65
+ const isMarked = typeSymbol[constants_1.LUABIND_SYMBOL] === true;
66
+ if (isMarked) {
67
+ return true;
68
+ }
69
+ else {
70
+ return isLuabindDecoratedClass(typeSymbol.declarations[0]);
71
+ }
72
+ }
73
+ else {
74
+ return false;
75
+ }
76
+ }
77
+ exports.isLuabindClassType = isLuabindClassType;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createErrorDiagnosticFactory = exports.createDiagnosticFactory = void 0;
4
+ const typescript_1 = require("typescript");
5
+ const utils_1 = require("typescript-to-lua/dist/utils");
6
+ /**
7
+ * Create diagnostics factory to push errors when transpile lua to typescript.
8
+ */
9
+ function createDiagnosticFactory(category, message) {
10
+ return (0, utils_1.createSerialDiagnosticFactory)((node, ...args) => ({
11
+ file: (0, typescript_1.getOriginalNode)(node).getSourceFile(),
12
+ start: (0, typescript_1.getOriginalNode)(node).getStart(),
13
+ length: (0, typescript_1.getOriginalNode)(node).getWidth(),
14
+ messageText: typeof message === "string" ? message : message(...args),
15
+ category,
16
+ }));
17
+ }
18
+ exports.createDiagnosticFactory = createDiagnosticFactory;
19
+ function createErrorDiagnosticFactory(message) {
20
+ return createDiagnosticFactory(typescript_1.DiagnosticCategory.Error, message);
21
+ }
22
+ exports.createErrorDiagnosticFactory = createErrorDiagnosticFactory;
@@ -0,0 +1,63 @@
1
+ import "./xr_lib/xr_fs";
2
+ import "./xr_lib/xr_math";
3
+ import "./xr_lib/xr_utils";
4
+ import "./xr_map/xr_map";
5
+ import "./xr_object/xr_action";
6
+ import "./xr_object/xr_alife";
7
+ import "./xr_object/xr_anomaly";
8
+ import "./xr_object/xr_artefact";
9
+ import "./xr_object/xr_client_object";
10
+ import "./xr_object/xr_creature";
11
+ import "./xr_object/xr_dialog";
12
+ import "./xr_object/xr_item";
13
+ import "./xr_object/xr_level";
14
+ import "./xr_object/xr_physic";
15
+ import "./xr_object/xr_quest";
16
+ import "./xr_object/xr_server_object";
17
+ import "./xr_online/xr_multiplayer";
18
+ import "./xr_sound/xr_sound";
19
+ import "./xr_type/xr_enums";
20
+ import "./xr_type/xr_type";
21
+ import "./xr_ui/xr_ui_core";
22
+ import "./xr_ui/xr_ui_interface";
23
+ import "./xr_constant";
24
+ import "./xr_core";
25
+ import "./xr_luabind";
26
+ import "./xr_global";
27
+
28
+ declare module "xray16" {
29
+ /**
30
+ * @group export
31
+ */
32
+ export const actor_stats: IXR_actor_stats;
33
+
34
+ /**
35
+ * @group export
36
+ */
37
+ export const ActorMenu: IXR_ActorMenu;
38
+
39
+ /**
40
+ * @group export
41
+ */
42
+ export const game: IXR_game;
43
+
44
+ /**
45
+ * @group export
46
+ */
47
+ export const level: IXR_level;
48
+
49
+ /**
50
+ * @group export
51
+ */
52
+ export const main_menu: IXR_main_menu;
53
+
54
+ /**
55
+ * @group export
56
+ */
57
+ export const object: typeof XR_object;
58
+
59
+ /**
60
+ * @group export
61
+ */
62
+ export const relation_registry: IXR_relation_registry;
63
+ }
@@ -1203,7 +1203,10 @@ declare module "xray16" {
1203
1203
  public command(entity_action: entity_action, is_high_priority: boolean): void;
1204
1204
  public hit(hit: hit): void;
1205
1205
  public inactualize_patrol_path(): void;
1206
- public iterate_inventory(cb: (this: void, owner: game_object, item: game_object) => void, object: game_object): void;
1206
+ public iterate_inventory(
1207
+ cb: (this: void, owner: game_object, item: game_object) => void,
1208
+ object: game_object
1209
+ ): void;
1207
1210
  public movement_enabled(): boolean;
1208
1211
  public movement_enabled(value: boolean): void;
1209
1212
  public set_condition(condition: f32): void;
@@ -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;