cluaupp 0.1.4 → 0.2.0

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 (113) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +12 -7
  3. package/bin/cluau.js +1 -1
  4. package/bin/cluaupp.js +1 -1
  5. package/docs/README.md +1 -1
  6. package/docs/architecture.md +52 -77
  7. package/docs/cli.md +29 -9
  8. package/docs/comparison.md +3 -3
  9. package/docs/config.md +6 -6
  10. package/docs/cpp-organization.md +2 -2
  11. package/docs/examples/index.md +2 -0
  12. package/docs/getting-started.md +7 -5
  13. package/docs/intellisense.md +49 -31
  14. package/docs/intro.md +2 -2
  15. package/docs/oop/file-tags.md +16 -17
  16. package/docs/oop/index.md +2 -2
  17. package/docs/oop/modules.md +3 -1
  18. package/docs/oop/services.md +7 -14
  19. package/docs/syntax.md +6 -5
  20. package/editors/vscode/extension.js +97 -146
  21. package/editors/vscode/package.json +6 -6
  22. package/examples/README.md +18 -0
  23. package/examples/game/.clangd +25 -0
  24. package/examples/game/.vscode/c_cpp_properties.json +27 -0
  25. package/examples/game/.vscode/extensions.json +5 -0
  26. package/examples/game/.vscode/settings.json +27 -0
  27. package/examples/game/Packages/.gitkeep +0 -0
  28. package/examples/game/cluaupp.config.json +6 -0
  29. package/examples/game/compile_flags.txt +6 -0
  30. package/examples/game/default.project.json +39 -0
  31. package/examples/game/package.json +9 -0
  32. package/examples/game/rokit.toml +5 -0
  33. package/examples/game/src/client/hud.client.cpp +12 -0
  34. package/{src → examples/game/src}/client/init.client.cpp +1 -0
  35. package/examples/game/src/server/combat.server.cpp +23 -0
  36. package/{src → examples/game/src}/server/leaderstats.server.cpp +1 -0
  37. package/examples/game/wally.toml +11 -0
  38. package/generated/api.js +51 -0
  39. package/generated/architecture.js +473 -0
  40. package/generated/ast.js +2 -0
  41. package/generated/cli.js +191 -0
  42. package/generated/compile.js +115 -0
  43. package/generated/editor-install.js +170 -0
  44. package/generated/emit.js +503 -0
  45. package/generated/emitter/luau-codegen.js +167 -0
  46. package/generated/emitter/translators.js +164 -0
  47. package/generated/headers.js +220 -0
  48. package/generated/index.html +49 -0
  49. package/generated/intellisense.js +277 -0
  50. package/generated/layout.js +112 -0
  51. package/generated/lex.js +146 -0
  52. package/generated/libs.js +484 -0
  53. package/generated/lsp.js +55 -0
  54. package/generated/package-info.js +11 -0
  55. package/generated/parse.js +607 -0
  56. package/generated/parser/collector.js +100 -0
  57. package/generated/parser/index.js +30 -0
  58. package/generated/preprocess.js +181 -0
  59. package/generated/system-understander.js +443 -0
  60. package/generated/transpile.js +66 -0
  61. package/generated/types.js +2 -0
  62. package/generated/understand.js +298 -0
  63. package/generated/utils/process-orchestrator.js +63 -0
  64. package/generated/utils/project.js +491 -0
  65. package/generated/utils/rojo-mapper.js +181 -0
  66. package/generated/utils/safe-paths.js +104 -0
  67. package/package.json +25 -8
  68. package/src/api.ts +53 -0
  69. package/src/{architecture.js → architecture.ts} +80 -33
  70. package/src/ast.ts +37 -0
  71. package/src/cli.ts +214 -0
  72. package/src/compile.ts +118 -0
  73. package/src/editor-install.ts +182 -0
  74. package/src/{emit.js → emit.ts} +5 -6
  75. package/src/emitter/luau-codegen.ts +187 -0
  76. package/src/emitter/translators.ts +168 -0
  77. package/src/headers.ts +233 -0
  78. package/src/intellisense.ts +286 -0
  79. package/src/{layout.js → layout.ts} +114 -129
  80. package/src/{lex.js → lex.ts} +4 -6
  81. package/src/{libs.js → libs.ts} +119 -46
  82. package/src/lsp.ts +60 -0
  83. package/src/package-info.ts +7 -0
  84. package/src/{parse.js → parse.ts} +3 -4
  85. package/src/parser/collector.ts +115 -0
  86. package/src/parser/index.ts +27 -0
  87. package/src/{preprocess.js → preprocess.ts} +64 -32
  88. package/src/system-understander.ts +501 -0
  89. package/src/transpile.ts +64 -0
  90. package/src/tree-sitter-cpp.d.ts +4 -0
  91. package/src/types.ts +81 -0
  92. package/src/{understand.js → understand.ts} +24 -213
  93. package/src/utils/process-orchestrator.ts +72 -0
  94. package/src/utils/project.ts +506 -0
  95. package/src/utils/rojo-mapper.ts +190 -0
  96. package/src/utils/safe-paths.ts +98 -0
  97. package/templates/game/.clangd +9 -0
  98. package/templates/game/.vscode/c_cpp_properties.json +1 -1
  99. package/templates/game/.vscode/extensions.json +5 -6
  100. package/templates/game/.vscode/settings.json +7 -6
  101. package/templates/game/cluaupp.config.json +2 -2
  102. package/templates/game/compile_flags.txt +1 -0
  103. package/templates/game/rokit.toml +5 -0
  104. package/templates/game/src/client/init.client.cpp +1 -0
  105. package/templates/game/src/server/leaderstats.server.cpp +1 -0
  106. package/src/api.js +0 -57
  107. package/src/cli.js +0 -481
  108. package/src/compile.js +0 -56
  109. package/src/editor-install.js +0 -218
  110. package/src/intellisense.js +0 -1368
  111. package/src/lsp.js +0 -227
  112. /package/{src → examples/game/src}/shared/config.cpp +0 -0
  113. /package/{src → examples/game/src}/shared/config.h +0 -0
@@ -0,0 +1,98 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ const BLOCKED_DIRS = new Set([".", "..", "node_modules", ".git"]);
6
+
7
+ export class PathEscapeError extends Error {
8
+ constructor(message: string) {
9
+ super(message);
10
+ this.name = "PathEscapeError";
11
+ }
12
+ }
13
+
14
+ export function posixRel(rel: string): string {
15
+ return String(rel || "").replace(/\\/g, "/");
16
+ }
17
+
18
+ export function isInside(root: string, target: string): boolean {
19
+ const absRoot = path.resolve(root);
20
+ const absTarget = path.resolve(target);
21
+ const rel = path.relative(absRoot, absTarget);
22
+ return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
23
+ }
24
+
25
+ export function realPath(target: string): string {
26
+ try {
27
+ return fs.realpathSync(target);
28
+ } catch {
29
+ return path.resolve(target);
30
+ }
31
+ }
32
+
33
+ export function assertInside(root: string, target: string, label: string): string {
34
+ const absRoot = realPath(root);
35
+ const absTarget = path.resolve(target);
36
+ if (!isInside(absRoot, absTarget)) {
37
+ throw new PathEscapeError(`cluaupp: ${label} escapes the project folder`);
38
+ }
39
+ return absTarget;
40
+ }
41
+
42
+ export function safeRelPath(rel: string): string | null {
43
+ const normalized = posixRel(rel).replace(/^\.\/+/, "");
44
+ if (!normalized || path.isAbsolute(normalized) || /^[a-zA-Z]:/.test(normalized)) {
45
+ return null;
46
+ }
47
+ const parts = normalized.split("/").filter((part) => part && part !== ".");
48
+ if (parts.length === 0 || parts.some((part) => part === ".." || part === ".git")) {
49
+ return null;
50
+ }
51
+ return parts.join("/");
52
+ }
53
+
54
+ export function safeProjectSubdir(value: string, fallback: string, label: string): string {
55
+ const cleaned = safeRelPath(value);
56
+ if (!cleaned || BLOCKED_DIRS.has(cleaned.split("/")[0] || "")) {
57
+ throw new PathEscapeError(`cluaupp: invalid ${label} ${JSON.stringify(value)}`);
58
+ }
59
+ return cleaned;
60
+ }
61
+
62
+ export function assertInitDest(dest: string): string {
63
+ const resolved = path.resolve(dest);
64
+ const root = path.parse(resolved).root;
65
+ if (resolved === root) {
66
+ throw new PathEscapeError("cluaupp: refused to init at the filesystem root");
67
+ }
68
+ const home = os.homedir();
69
+ if (home && path.resolve(home) === resolved) {
70
+ throw new PathEscapeError("cluaupp: refused to init in the home directory itself");
71
+ }
72
+ return resolved;
73
+ }
74
+
75
+ export function childEnv(): NodeJS.ProcessEnv {
76
+ const env: NodeJS.ProcessEnv = {};
77
+ for (const key of [
78
+ "PATH",
79
+ "Path",
80
+ "PATHEXT",
81
+ "SYSTEMROOT",
82
+ "SystemRoot",
83
+ "COMSPEC",
84
+ "ComSpec",
85
+ "HOME",
86
+ "USERPROFILE",
87
+ "TMP",
88
+ "TEMP",
89
+ "TMPDIR",
90
+ "LANG",
91
+ "LC_ALL",
92
+ ]) {
93
+ if (process.env[key]) {
94
+ env[key] = process.env[key];
95
+ }
96
+ }
97
+ return env;
98
+ }
@@ -1,14 +1,23 @@
1
1
  CompileFlags:
2
+ CompilationDatabase: .
2
3
  Add:
3
4
  - -xc++
4
5
  - -std=c++20
5
6
  - -ferror-limit=0
6
7
  - -Iinclude
7
8
  - -Isrc
9
+ - -I../../include
8
10
 
9
11
  Diagnostics:
10
12
  Suppress: '*'
11
13
 
14
+ ---
15
+ If:
16
+ PathMatch: .*\.(cpp|cc|cxx|c|h|hpp|hh)$
17
+ CompileFlags:
18
+ Add:
19
+ - -xc++
20
+
12
21
  ---
13
22
  If:
14
23
  PathMatch: (out|libs)/.*
@@ -2,7 +2,7 @@
2
2
  "configurations": [
3
3
  {
4
4
  "name": "Cluaupp",
5
- "compilerPath": "C:/Program Files/LLVM/bin/clang++.exe",
5
+ "compilerPath": "clang++",
6
6
  "cStandard": "c17",
7
7
  "cppStandard": "c++20",
8
8
  "intelliSenseMode": "windows-clang-x64",
@@ -1,6 +1,5 @@
1
- {
2
- "recommendations": [
3
- "ms-vscode.cpptools",
4
- "kartzdev.cluaupp-intellisense"
5
- ]
6
- }
1
+ {
2
+ "recommendations": [
3
+ "llvm-vs-code-extensions.vscode-clangd"
4
+ ]
5
+ }
@@ -1,18 +1,19 @@
1
1
  {
2
- "C_Cpp.intelliSenseEngine": "default",
2
+ "C_Cpp.intelliSenseEngine": "Disabled",
3
3
  "C_Cpp.default.cppStandard": "c++20",
4
4
  "C_Cpp.default.cStandard": "c17",
5
- "C_Cpp.default.compilerPath": "C:/Program Files/LLVM/bin/clang++.exe",
5
+ "C_Cpp.default.compilerPath": "clang++",
6
6
  "C_Cpp.default.intelliSenseMode": "windows-clang-x64",
7
7
  "C_Cpp.default.includePath": [
8
8
  "${workspaceFolder}/include",
9
9
  "${workspaceFolder}/src"
10
10
  ],
11
- "C_Cpp.default.browse.path": [
12
- "${workspaceFolder}/include",
13
- "${workspaceFolder}/src"
11
+ "clangd.enable": true,
12
+ "clangd.arguments": [
13
+ "--compile-commands-dir=${workspaceFolder}",
14
+ "--header-insertion=never",
15
+ "--query-driver=**/clang++*,**/clang++.exe,**/g++*,**/g++.exe"
14
16
  ],
15
- "clangd.enable": false,
16
17
  "files.associations": {
17
18
  "*.hpp": "cpp",
18
19
  "*.h": "cpp",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "rootDir": "src",
3
3
  "outDir": "out",
4
- "strict": true,
5
- "architecture": true
4
+ "strict": false,
5
+ "architecture": false
6
6
  }
@@ -3,3 +3,4 @@
3
3
  -ferror-limit=0
4
4
  -Iinclude
5
5
  -Isrc
6
+ -I../../include
@@ -0,0 +1,5 @@
1
+ # This file lists tools managed by Rokit, a toolchain manager for Roblox projects.
2
+ # https://github.com/rojo-rbx/rokit
3
+
4
+ [tools]
5
+ rojo = "rojo-rbx/rojo@7.7.0"
@@ -1,3 +1,4 @@
1
+ #pragma strict
1
2
  #include <cluaupp/roblox.hpp>
2
3
 
3
4
  void init() {
@@ -1,3 +1,4 @@
1
+ #pragma strict
1
2
  #include <cluaupp/roblox.hpp>
2
3
 
3
4
  void CreateLeaderstats(Player* player) {
package/src/api.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- const generated = require("./api.generated");
4
-
5
- const INSTANCE_TYPES = new Set(generated.INSTANCE_TYPES);
6
- const SERVICES = new Set(generated.SERVICES);
7
- const METHODS = new Set(generated.METHODS);
8
- const DATATYPES = new Set(generated.DATATYPES);
9
-
10
- const LUAU_TYPES = {
11
- void: "()",
12
- int: "number",
13
- float: "number",
14
- double: "number",
15
- bool: "boolean",
16
- string: "string",
17
- auto: null,
18
- };
19
-
20
- function isInstanceType(name) {
21
- return INSTANCE_TYPES.has(name);
22
- }
23
-
24
- function isService(name) {
25
- return SERVICES.has(name);
26
- }
27
-
28
- function isMethod(name) {
29
- return METHODS.has(name);
30
- }
31
-
32
- function isDatatype(name) {
33
- return DATATYPES.has(name);
34
- }
35
-
36
- function luauType(name) {
37
- if (!name) {
38
- return null;
39
- }
40
- const cleaned = String(name).replace(/\*+$/, "").replace(/^const\s+/, "").replace(/^Enum::/, "Enum.");
41
- if (cleaned in LUAU_TYPES) {
42
- return LUAU_TYPES[cleaned];
43
- }
44
- return cleaned;
45
- }
46
-
47
- module.exports = {
48
- INSTANCE_TYPES,
49
- SERVICES,
50
- METHODS,
51
- DATATYPES,
52
- isInstanceType,
53
- isService,
54
- isMethod,
55
- isDatatype,
56
- luauType,
57
- };