@overmvp/kumi 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +14 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +334 -0
- package/builder/css-v1.test.mjs +321 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +86 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +444 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2164 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/animation.ts +428 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/start-addon.ts +99 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { transformSecureSnippets } from "./secure-snippet.mjs";
|
|
6
|
+
|
|
7
|
+
const normalize = path => path.replaceAll("\\", "/");
|
|
8
|
+
const path = normalize(fileURLToPath(new URL("./secure-snippet.fixture.ts", import.meta.url)));
|
|
9
|
+
const declarations = normalize(fileURLToPath(new URL("./secure-snippet.fixture.d.ts", import.meta.url)));
|
|
10
|
+
const prelude = 'import { secureSnippet as compile } from "@kumi/wow";\n';
|
|
11
|
+
|
|
12
|
+
function transform(body) {
|
|
13
|
+
const source = prelude + body;
|
|
14
|
+
const files = new Map([[path, source], [declarations, `
|
|
15
|
+
declare module "@kumi/wow" {
|
|
16
|
+
export interface Handle {
|
|
17
|
+
GetFrameRef(key: string): Handle | undefined;
|
|
18
|
+
SetAttribute(key: string, value: string): void;
|
|
19
|
+
Hide(): void;
|
|
20
|
+
}
|
|
21
|
+
export function secureSnippet(body: (frame: Handle, button: string, down: boolean, control: Handle) => unknown,
|
|
22
|
+
options?: { event?: string; refs?: Record<string, object> }): object;
|
|
23
|
+
}
|
|
24
|
+
`]]);
|
|
25
|
+
const options = { target: ts.ScriptTarget.ES2020, strict: true, noEmit: true, skipLibCheck: true };
|
|
26
|
+
const host = ts.createCompilerHost(options);
|
|
27
|
+
const get = host.getSourceFile;
|
|
28
|
+
host.getSourceFile = (name, language, ...rest) => {
|
|
29
|
+
const input = files.get(normalize(name));
|
|
30
|
+
return input === undefined ? get(name, language, ...rest) : ts.createSourceFile(name, input, language, true);
|
|
31
|
+
};
|
|
32
|
+
return transformSecureSnippets(ts, path, source, { program: ts.createProgram([...files.keys()], options, host) });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function bodies(output) {
|
|
36
|
+
return [...output.matchAll(/compile\(("(?:[^"\\]|\\.)*") as never/g)].map(([, body]) => JSON.parse(body));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
test("emits standalone Lua using client arguments and preserving multiple returns", () => {
|
|
40
|
+
const output = transform(`declare const popup: object;
|
|
41
|
+
const snippet = compile((_buttonFrame, clicked, pressed, header) => {
|
|
42
|
+
const target = header.GetFrameRef("popup");
|
|
43
|
+
if (target !== undefined && clicked === "RightButton" && pressed) {
|
|
44
|
+
target.Hide();
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return [undefined, true];
|
|
48
|
+
}, { refs: { popup } });
|
|
49
|
+
`);
|
|
50
|
+
assert.deepEqual(bodies(output), [[
|
|
51
|
+
'local local1_target = control:GetFrameRef("popup")',
|
|
52
|
+
'if (((local1_target ~= nil) and (button == "RightButton")) and down) then',
|
|
53
|
+
' local1_target:Hide()',
|
|
54
|
+
' return false',
|
|
55
|
+
'end',
|
|
56
|
+
'return nil, true',
|
|
57
|
+
].join("\n")]);
|
|
58
|
+
assert.match(output, /refs: \{ popup \}/);
|
|
59
|
+
assert.doesNotMatch(output, /__TS__|=>/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("emits a local loop and Lua byte escapes for control characters", () => {
|
|
63
|
+
const output = transform(`compile(frame => {
|
|
64
|
+
for (let index = 1; index < 3; index++) {
|
|
65
|
+
frame.SetAttribute("slot-" + index, "a\\n\\x01");
|
|
66
|
+
}
|
|
67
|
+
});`);
|
|
68
|
+
assert.deepEqual(bodies(output), [[
|
|
69
|
+
'do',
|
|
70
|
+
' local local1_index = 1',
|
|
71
|
+
' while (local1_index < 3) do',
|
|
72
|
+
' do',
|
|
73
|
+
' self:SetAttribute(("slot-" .. local1_index), "a\\010\\001")',
|
|
74
|
+
' end',
|
|
75
|
+
' local1_index = local1_index + 1',
|
|
76
|
+
' end',
|
|
77
|
+
'end',
|
|
78
|
+
].join("\n")]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("reports unsupported bindings and expressions at their original locations", async t => {
|
|
82
|
+
const cases = [
|
|
83
|
+
["captured local", 'const outside = false;\ncompile(() => outside);', /:3:\d+: Secure snippet cannot capture outside/],
|
|
84
|
+
["native dynamic execution", 'compile(frame => frame.Run("return true"));', /:2:\d+: Expected an allowed restricted function/],
|
|
85
|
+
["unknown global", 'compile(() => loadstring("return true"));', /:2:\d+: Expected an allowed restricted function/],
|
|
86
|
+
["undeclared WoW global", 'compile(() => GetMouseFocus());', /:2:\d+: Expected an allowed restricted function/],
|
|
87
|
+
["undeclared identifier", 'compile(() => foo);', /:2:\d+: Secure snippet cannot capture foo/],
|
|
88
|
+
["undeclared library function", 'compile(() => format("x"));', /:2:\d+: Expected an allowed restricted function/],
|
|
89
|
+
["dynamic ref", 'compile((frame, key) => frame.GetFrameRef(key));', /:2:\d+: GetFrameRef requires a literal key declared in refs/],
|
|
90
|
+
["ref receiver", 'compile(frame => frame.GetFrameRef("popup"), { refs: { popup: {} } });', /:2:\d+: Read declared frame references through the control parameter/],
|
|
91
|
+
["optional chaining", 'compile(frame => frame.GetFrameRef("popup")?.Hide());', /:2:\d+: Optional calls are unsupported/],
|
|
92
|
+
["spread", 'compile(frame => frame.SetAttribute(...["key", "value"]));', /:2:\d+: Unsupported secure expression SpreadElement/],
|
|
93
|
+
["script attributes", 'compile(frame => frame.SetAttribute("_onclick", "bad"));', /:2:\d+: Secure handlers cannot replace scripts/],
|
|
94
|
+
["marker alias", 'const indirect = compile;', /:2:\d+: Use secureSnippet as a direct call/],
|
|
95
|
+
["handwritten text", 'compile("return false" as never);', /:2:\d+: Pass a synchronous inline arrow/],
|
|
96
|
+
["type error", 'compile(frame => frame.SetAttribute("field", 42));', /:2:\d+: Argument of type 'number'/],
|
|
97
|
+
];
|
|
98
|
+
for (const [name, input, error] of cases) {
|
|
99
|
+
await t.test(name, () => assert.throws(() => transform(input), error));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
export const sharedLuaKey = "lualib_bundle";
|
|
4
|
+
export const sharedLuaPath = "KumiGenerated/SharedRuntime.lua";
|
|
5
|
+
const expectedCompiler = "1.37.1";
|
|
6
|
+
const schema = 1;
|
|
7
|
+
const standardGlobals = new Set([
|
|
8
|
+
"_G", "_VERSION", "coroutine", "debug", "error", "getmetatable", "ipairs", "math", "next", "pairs",
|
|
9
|
+
"rawget", "rawset", "select", "setmetatable", "string", "table", "tonumber", "tostring", "type", "unpack", "xpcall",
|
|
10
|
+
]);
|
|
11
|
+
const globalMembers = new Set([
|
|
12
|
+
"pcall", "coroutine", "getmetatable", "rawget", "rawset", "__TS__sourcemap", "__TS__originalTraceback",
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
function parseChunk(parse, text) {
|
|
16
|
+
return parse(text, { luaVersion: "5.1", scope: true, ranges: true, comments: false });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function visit(node, callback, parent, depth = 0) {
|
|
20
|
+
callback(node, parent, depth);
|
|
21
|
+
const nested = depth + (node.type === "FunctionDeclaration" ? 1 : 0);
|
|
22
|
+
for (const [property, value] of Object.entries(node)) {
|
|
23
|
+
if (property === "globals") continue;
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
for (const child of value) if (child?.type) visit(child, callback, node, nested);
|
|
26
|
+
} else if (value?.type) visit(value, callback, node, nested);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function checkFactoryContext(chunk) {
|
|
31
|
+
for (const binding of chunk.globals) {
|
|
32
|
+
if (!standardGlobals.has(binding.name)) throw new Error(`Shared ${sharedLuaKey} reads unbound ${binding.name}`);
|
|
33
|
+
}
|
|
34
|
+
visit(chunk, (node, parent, depth) => {
|
|
35
|
+
if (node.type === "VarargLiteral" && depth === 0) throw new Error(`Shared ${sharedLuaKey} reads consumer varargs`);
|
|
36
|
+
if (node.type === "Identifier" && node.name === "_G" && node.isLocal === false &&
|
|
37
|
+
(parent?.type !== "MemberExpression" || parent.base !== node || !globalMembers.has(parent.identifier.name))) {
|
|
38
|
+
throw new Error(`Shared ${sharedLuaKey} reads a non-portable global table member`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function listExports(body) {
|
|
44
|
+
const returned = body.at(-1);
|
|
45
|
+
const table = returned?.type === "ReturnStatement" && returned.arguments.length === 1 && returned.arguments[0];
|
|
46
|
+
if (table?.type !== "TableConstructorExpression") throw new Error(`Shared ${sharedLuaKey} must return a named export table`);
|
|
47
|
+
const bindings = new Map();
|
|
48
|
+
for (const field of table.fields) {
|
|
49
|
+
const name = field.type === "TableKeyString" ? field.key.name : undefined;
|
|
50
|
+
if (!name || field.value.type !== "Identifier" || field.value.isLocal !== true ||
|
|
51
|
+
(bindings.has(name) && bindings.get(name) !== field.value.name)) {
|
|
52
|
+
throw new Error(`Invalid shared ${sharedLuaKey} export ${name ?? "<unnamed>"}`);
|
|
53
|
+
}
|
|
54
|
+
// TSTL 1.37.1 repeats the identical ParseFloat and ParseInt export bindings.
|
|
55
|
+
bindings.set(name, field.value.name);
|
|
56
|
+
}
|
|
57
|
+
if (bindings.size === 0) throw new Error(`Shared ${sharedLuaKey} has no exports`);
|
|
58
|
+
return [...bindings.keys()].sort();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createSharedLuaRuntime({ parse, library, compiler, target }) {
|
|
62
|
+
if (compiler !== expectedCompiler || target !== "5.1") {
|
|
63
|
+
throw new Error(`Shared Lua requires TSTL ${expectedCompiler} / Lua 5.1; got TSTL ${compiler} / Lua ${target}. Update the pin and rebuild every bundle together.`);
|
|
64
|
+
}
|
|
65
|
+
const normalized = library.replaceAll("\r\n", "\n").trimEnd();
|
|
66
|
+
// TSTL 1.37.1 guards stack collection but not Error stringification. WoW has no debug table.
|
|
67
|
+
const callerLookup = 'local caller = debug.getinfo(3, "f")';
|
|
68
|
+
const callerIndex = normalized.indexOf(callerLookup);
|
|
69
|
+
const factory = normalized.replace(callerLookup,
|
|
70
|
+
`if debug == nil then return description end\n ${callerLookup}`);
|
|
71
|
+
const chunk = parseChunk(parse, factory);
|
|
72
|
+
checkFactoryContext(chunk);
|
|
73
|
+
const exports = listExports(chunk.body);
|
|
74
|
+
if (exports.includes("Error") && (callerIndex === -1 || normalized.indexOf(callerLookup, callerIndex + callerLookup.length) !== -1)) {
|
|
75
|
+
throw new Error("Pinned TSTL Error stringifier has changed");
|
|
76
|
+
}
|
|
77
|
+
const manifest = { schema, compiler, target, modules: [{ key: sharedLuaKey, exports, hash: sha256(factory) }] };
|
|
78
|
+
const stamp = `kumi-shared/${schema};tstl=${compiler};lua=${target};sha256=${sha256(JSON.stringify(manifest))}`;
|
|
79
|
+
const quotedStamp = JSON.stringify(stamp);
|
|
80
|
+
const source = `local _, addonTable = ...
|
|
81
|
+
local function libraryFactory()
|
|
82
|
+
${factory}
|
|
83
|
+
end
|
|
84
|
+
local libraryExports
|
|
85
|
+
local function sharedRequire(key)
|
|
86
|
+
if key ~= "${sharedLuaKey}" then error("Unknown shared Lua module " .. tostring(key), 2) end
|
|
87
|
+
if libraryExports == nil then libraryExports = libraryFactory() end
|
|
88
|
+
return libraryExports
|
|
89
|
+
end
|
|
90
|
+
assert(type(addonTable) == "table", "Shared Lua requires the core addon table")
|
|
91
|
+
assert(addonTable.KumiSharedLua == nil, "Duplicate shared Lua registry")
|
|
92
|
+
addonTable.KumiSharedLua = {
|
|
93
|
+
Stamp = ${quotedStamp},
|
|
94
|
+
Require = sharedRequire,
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
return { manifest, stamp, source };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function sha256(value) { return createHash("sha256").update(value).digest("hex"); }
|
|
101
|
+
|
|
102
|
+
function sharedField(field) {
|
|
103
|
+
return field.type === "TableKey" && /^(["'])lualib_bundle\1$/.test(field.key.raw ?? "");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function externalizeSharedLuaBundle(lua, { parse, runtime }) {
|
|
107
|
+
const tree = parseChunk(parse, lua);
|
|
108
|
+
const registry = tree.body.find(node => node.type === "AssignmentStatement" && node.variables[0]?.name === "____modules")?.init[0];
|
|
109
|
+
if (registry?.type !== "TableConstructorExpression") throw new Error("TSTL Lua module registry is missing");
|
|
110
|
+
const shared = registry.fields.filter(sharedField);
|
|
111
|
+
if (shared.length > 1) throw new Error(`Duplicate bundled ${sharedLuaKey}`);
|
|
112
|
+
const [entry] = shared;
|
|
113
|
+
if (!entry) return lua;
|
|
114
|
+
if (entry.value.type !== "FunctionDeclaration") throw new Error(`Invalid bundled ${sharedLuaKey} loader`);
|
|
115
|
+
const available = new Set(runtime.manifest.modules[0].exports);
|
|
116
|
+
for (const name of listExports(entry.value.body)) {
|
|
117
|
+
if (!available.has(name)) throw new Error(`Shared ${sharedLuaKey} is missing ${name}`);
|
|
118
|
+
}
|
|
119
|
+
const [start, end] = entry.range;
|
|
120
|
+
const [, tableEnd] = registry.range;
|
|
121
|
+
const separator = /^\s*[,;]/.exec(lua.slice(end, tableEnd));
|
|
122
|
+
// The preceding field may retain its trailing comma.
|
|
123
|
+
const stop = separator ? end + separator[0].length : end;
|
|
124
|
+
return lua.slice(0, start) + lua.slice(start, stop).replace(/[^\n]/g, "") + lua.slice(stop);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function bindSharedLuaConsumer({ stamp }) {
|
|
128
|
+
return `local __kumiSharedLua = App.KumiSharedLua
|
|
129
|
+
local __kumiSharedStamp = ${JSON.stringify(stamp)}
|
|
130
|
+
local __kumiActualStamp = type(__kumiSharedLua) == "table" and __kumiSharedLua.Stamp
|
|
131
|
+
if __kumiActualStamp ~= __kumiSharedStamp then
|
|
132
|
+
error("Lua runtime mismatch for " .. addonName .. ": expected " .. __kumiSharedStamp .. ", got " .. tostring(__kumiActualStamp or "missing"), 0)
|
|
133
|
+
end
|
|
134
|
+
local __kumiFallbackRequire = require
|
|
135
|
+
local function require(key)
|
|
136
|
+
if key == "${sharedLuaKey}" then return __kumiSharedLua.Require(key) end
|
|
137
|
+
if __kumiFallbackRequire then return __kumiFallbackRequire(key) end
|
|
138
|
+
error("Unknown Lua module " .. tostring(key), 2)
|
|
139
|
+
end
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function verifySharedLuaConsumer(lua, { parse, stamp }) {
|
|
144
|
+
let stamps = 0;
|
|
145
|
+
visit(parseChunk(parse, lua), node => {
|
|
146
|
+
if (sharedField(node)) throw new Error(`Emitted Lua duplicates shared ${sharedLuaKey}`);
|
|
147
|
+
if (node.type === "StringLiteral" && node.raw === JSON.stringify(stamp)) stamps++;
|
|
148
|
+
});
|
|
149
|
+
if (stamps !== 1) throw new Error(`Emitted Lua expects exactly one shared runtime stamp, found ${stamps}`);
|
|
150
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
if type(addonApp) ~= "table" then error("A native WoW addon requires its shared addon table", 0) end
|
|
2
|
+
local nativeRegistry = rawget(addonApp, "KumiNativeLua")
|
|
3
|
+
if nativeRegistry == nil then
|
|
4
|
+
nativeRegistry = { abi = 2, build = nativeBuild, modules = {}, classPrototypes = setmetatable({}, { __mode = "kv" }) }
|
|
5
|
+
rawset(addonApp, "KumiNativeLua", nativeRegistry)
|
|
6
|
+
elseif type(nativeRegistry) ~= "table" or nativeRegistry.abi ~= 2 or nativeRegistry.build ~= nativeBuild then
|
|
7
|
+
error("Native Kumi runtime mismatch for " .. tostring(addonName), 0)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
local sharedModules = nativeRegistry.modules
|
|
11
|
+
local function cachedNativeModule(key, fingerprint)
|
|
12
|
+
local entry = sharedModules[key]
|
|
13
|
+
if entry == nil then return end
|
|
14
|
+
if entry.fingerprint ~= fingerprint then error("Native Kumi module mismatch for " .. key, 0) end
|
|
15
|
+
if entry.value == nil then error("Circular native Kumi initialization of " .. key, 0) end
|
|
16
|
+
return entry.value
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
local function initializeNativeModule(key, fingerprint, initialize, ...)
|
|
20
|
+
local entry = { fingerprint = fingerprint }
|
|
21
|
+
sharedModules[key] = entry
|
|
22
|
+
local ok, value = pcall(initialize, ...)
|
|
23
|
+
if not ok then
|
|
24
|
+
sharedModules[key] = nil
|
|
25
|
+
error(value, 0)
|
|
26
|
+
end
|
|
27
|
+
entry.value = value
|
|
28
|
+
return value
|
|
29
|
+
end
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
local arrays = {}
|
|
2
|
+
|
|
3
|
+
local function isLuaArray(value)
|
|
4
|
+
return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
local function arrayOffset(offset, length, default)
|
|
8
|
+
if offset == nil then return default end
|
|
9
|
+
if offset ~= offset then return 0 end
|
|
10
|
+
if offset < 0 then return math.max(0, length + math.ceil(offset)) end
|
|
11
|
+
return math.min(length, math.floor(offset))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
local function arrayIncludes(array, expected, offset)
|
|
15
|
+
local length = #array
|
|
16
|
+
local start = offset ~= nil and arrayOffset(offset, length, 0) or 0
|
|
17
|
+
for index = start + 1, length do
|
|
18
|
+
local item = array[index]
|
|
19
|
+
if rawequal(item, expected) or item ~= item and expected ~= expected then return true end
|
|
20
|
+
end
|
|
21
|
+
return false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
local function arrayIndexOf(array, expected, offset)
|
|
25
|
+
local length = #array
|
|
26
|
+
local start = offset ~= nil and arrayOffset(offset, length, 0) or 0
|
|
27
|
+
for index = start + 1, length do
|
|
28
|
+
if rawequal(array[index], expected) then return index - 1 end
|
|
29
|
+
end
|
|
30
|
+
return -1
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
local function arraySlice(array, start, stop)
|
|
34
|
+
local length = #array
|
|
35
|
+
local result = {}
|
|
36
|
+
local first = arrayOffset(start, length, 0)
|
|
37
|
+
for index = first + 1, arrayOffset(stop, length, length) do result[index - first] = array[index] end
|
|
38
|
+
return result
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
local function arrayFromLength(length, map)
|
|
42
|
+
local result = {}
|
|
43
|
+
if length ~= length or length <= 0 then return result end
|
|
44
|
+
if length >= 4294967296 then error("Invalid array length", 2) end
|
|
45
|
+
for index = 1, math.floor(length) do result[index] = map(nil, index - 1) end
|
|
46
|
+
return result
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
local function arrayReduce(array, reduce, initial)
|
|
50
|
+
local result = initial
|
|
51
|
+
for index = 1, #array do result = reduce(result, array[index], index - 1, array) end
|
|
52
|
+
return result
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
local function arrayJoin(array, separator)
|
|
56
|
+
local parts = {}
|
|
57
|
+
for index = 1, #array do parts[index] = tostring(array[index]) end
|
|
58
|
+
return table.concat(parts, separator or ",")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
local function arrayShift(array)
|
|
62
|
+
return table.remove(array, 1)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
local function arrayReverse(array)
|
|
66
|
+
local length = #array
|
|
67
|
+
for left = 1, math.floor(length / 2) do
|
|
68
|
+
local right = length - left + 1
|
|
69
|
+
array[left], array[right] = array[right], array[left]
|
|
70
|
+
end
|
|
71
|
+
return array
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
local function arrayTakeTail(array, offset)
|
|
75
|
+
local length = #array
|
|
76
|
+
local start = arrayOffset(offset, length, 0)
|
|
77
|
+
local tail = {}
|
|
78
|
+
for index = start + 1, length do tail[#tail + 1] = array[index] end
|
|
79
|
+
for index = length, start + 1, -1 do array[index] = nil end
|
|
80
|
+
return tail
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
local function arraySplice(array, offset, count)
|
|
84
|
+
local removed = {}
|
|
85
|
+
if count == nil or not (count > 0) then return removed end
|
|
86
|
+
local length = #array
|
|
87
|
+
local first = arrayOffset(offset, length, 0)
|
|
88
|
+
local removedCount = math.min(length - first, math.floor(count))
|
|
89
|
+
if removedCount == 0 then return removed end
|
|
90
|
+
for index = 1, removedCount do removed[index] = array[first + index] end
|
|
91
|
+
for index = first + 1, length - removedCount do array[index] = array[index + removedCount] end
|
|
92
|
+
for index = length, length - removedCount + 1, -1 do array[index] = nil end
|
|
93
|
+
return removed
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
local function arraySpliceInsert(array, offset, count, ...)
|
|
97
|
+
local length = #array
|
|
98
|
+
local first = arrayOffset(offset, length, 0)
|
|
99
|
+
local removedCount = count ~= nil and count > 0 and math.min(length - first, math.floor(count)) or 0
|
|
100
|
+
local removed = {}
|
|
101
|
+
for index = 1, removedCount do removed[index] = array[first + index] end
|
|
102
|
+
local insertedCount = select("#", ...)
|
|
103
|
+
local shift = insertedCount - removedCount
|
|
104
|
+
if shift > 0 then
|
|
105
|
+
for index = length, first + removedCount + 1, -1 do array[index + shift] = array[index] end
|
|
106
|
+
elseif shift < 0 then
|
|
107
|
+
for index = first + removedCount + 1, length do array[index + shift] = array[index] end
|
|
108
|
+
for index = length, length + shift + 1, -1 do array[index] = nil end
|
|
109
|
+
end
|
|
110
|
+
for index = 1, insertedCount do array[first + index] = select(index, ...) end
|
|
111
|
+
return removed
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
local function arraySort(array, compare, usesSelf)
|
|
115
|
+
if compare == nil then table.sort(array)
|
|
116
|
+
elseif usesSelf then table.sort(array, function(left, right) return compare(nil, left, right) < 0 end)
|
|
117
|
+
else table.sort(array, function(left, right) return compare(left, right) < 0 end) end
|
|
118
|
+
return array
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
local function arrayEvery(array, test)
|
|
122
|
+
for index = 1, #array do
|
|
123
|
+
if not test(array[index], index - 1, array) then return false end
|
|
124
|
+
end
|
|
125
|
+
return true
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
local function arraySome(array, test)
|
|
129
|
+
for index = 1, #array do
|
|
130
|
+
if test(array[index], index - 1, array) then return true end
|
|
131
|
+
end
|
|
132
|
+
return false
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
local function arrayMap(array, map)
|
|
136
|
+
local result = {}
|
|
137
|
+
for index = 1, #array do result[index] = map(array[index], index - 1, array) end
|
|
138
|
+
return result
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
local function arrayFilter(array, test)
|
|
142
|
+
local result = {}
|
|
143
|
+
local write = 1
|
|
144
|
+
for index = 1, #array do
|
|
145
|
+
local item = array[index]
|
|
146
|
+
if test(item, index - 1, array) then
|
|
147
|
+
result[write] = item
|
|
148
|
+
write = write + 1
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
return result
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
local function arrayFindIndex(array, test)
|
|
155
|
+
for index = 1, #array do
|
|
156
|
+
if test(array[index], index - 1, array) then return index - 1 end
|
|
157
|
+
end
|
|
158
|
+
return -1
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
local function arrayFind(array, test)
|
|
162
|
+
for index = 1, #array do
|
|
163
|
+
local value = array[index]
|
|
164
|
+
if test(value, index - 1, array) then return value end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
local function arrayAppend(target, source)
|
|
169
|
+
local offset = #target
|
|
170
|
+
for index = 1, #source do target[offset + index] = source[index] end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
local function arrayConcat(first, ...)
|
|
174
|
+
local result = arraySlice(first)
|
|
175
|
+
for index = 1, select("#", ...) do arrayAppend(result, (select(index, ...))) end
|
|
176
|
+
return result
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
local function arrayPushAll(target, source)
|
|
180
|
+
arrayAppend(target, source)
|
|
181
|
+
return #target
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
local function arrayPushValues(target, ...)
|
|
185
|
+
local offset, count = #target, select("#", ...)
|
|
186
|
+
for index = 1, count do
|
|
187
|
+
local value = select(index, ...)
|
|
188
|
+
if value == nil then error("Cannot append nil to a dense Kumi array", 2) end
|
|
189
|
+
target[offset + index] = value
|
|
190
|
+
end
|
|
191
|
+
return offset + count
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
local function arrayPushSlots(array, ...)
|
|
195
|
+
local offset, count = #array, select("#", ...)
|
|
196
|
+
for index = 1, count do array[offset + index] = select(index, ...) end
|
|
197
|
+
return offset + count
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
local function arrayUnshift(target, ...)
|
|
201
|
+
local length, count = #target, select("#", ...)
|
|
202
|
+
if count == 0 then return length end
|
|
203
|
+
for index = length, 1, -1 do target[index + count] = target[index] end
|
|
204
|
+
for index = 1, count do
|
|
205
|
+
local value = select(index, ...)
|
|
206
|
+
if value == nil then error("Cannot prepend nil to a dense Kumi array", 2) end
|
|
207
|
+
target[index] = value
|
|
208
|
+
end
|
|
209
|
+
return length + count
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
local function arrayFlatMap(array, map)
|
|
213
|
+
local result = {}
|
|
214
|
+
local next = 1
|
|
215
|
+
for index = 1, #array do
|
|
216
|
+
local value = map(array[index], index - 1, array)
|
|
217
|
+
if isLuaArray(value) then
|
|
218
|
+
for entry = 1, #value do
|
|
219
|
+
result[next] = value[entry]
|
|
220
|
+
next = next + 1
|
|
221
|
+
end
|
|
222
|
+
else
|
|
223
|
+
result[next] = value
|
|
224
|
+
next = next + 1
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
return result
|
|
228
|
+
end
|
|
229
|
+
function arrays.push(array, value)
|
|
230
|
+
if value == nil then error("Cannot append nil to a dense Kumi array", 2) end
|
|
231
|
+
local next = #array + 1
|
|
232
|
+
array[next] = value
|
|
233
|
+
return next
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
local function arrayForEach(array, effect)
|
|
237
|
+
for index = 1, #array do effect(array[index], index - 1, array) end
|
|
238
|
+
end
|
|
239
|
+
function arrays.pop(array)
|
|
240
|
+
local last = #array
|
|
241
|
+
if last == 0 then return end
|
|
242
|
+
local value = array[last]
|
|
243
|
+
array[last] = nil
|
|
244
|
+
return value
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
function arrays.write(array, offset, value)
|
|
248
|
+
if type(offset) ~= "number" or offset < 0 or offset > #array or offset % 1 ~= 0 or value == nil then
|
|
249
|
+
error("Cannot create a hole in a dense Kumi array", 2)
|
|
250
|
+
end
|
|
251
|
+
array[offset + 1] = value
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
function arrays.trim(array, length)
|
|
255
|
+
local previous = #array
|
|
256
|
+
if type(length) ~= "number" or length < 0 or length > previous or length % 1 ~= 0 then
|
|
257
|
+
error("Dense Kumi arrays can only shrink by changing length", 2)
|
|
258
|
+
end
|
|
259
|
+
for index = previous, length + 1, -1 do array[index] = nil end
|
|
260
|
+
end
|