Skip to content

Commit bb45dcd

Browse files
committed
Add lua library functions to keyword linker
1 parent ee948e0 commit bb45dcd

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

web/public/mta-keyword_linker.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
let allFunctions = new Set();
22

33
const wantedScopes = new Set([
4-
"support.function.mta-shared",
5-
"support.function.mta-server",
6-
"support.function.mta-client",
7-
"keyword.mta"
4+
"support.function.mta-shared",
5+
"support.function.mta-server",
6+
"support.function.mta-client",
7+
"keyword.mta",
8+
"support.function.library.lua"
89
]);
910

1011
function extractFunctions(tmLanguage, textContent) {
@@ -19,16 +20,28 @@ function extractFunctions(tmLanguage, textContent) {
1920
while ((m = regex.exec(textContent)) !== null) {
2021
if (m[0]) result.add(m[0]);
2122
}
23+
return;
24+
} else if (name === "support.function.library.lua") {
25+
const regex = /([a-zA-Z0-9_]+)\\?\.\(([^)]+)\)/g;
26+
const matches = [...match.matchAll(regex)];
27+
28+
matches.forEach(m => {
29+
const lib = m[1];
30+
const funcs = m[2].split("|");
31+
funcs.forEach(fn => result.add(`${lib}.${fn}`));
32+
});
33+
return;
2234
} else {
2335
const matches = match.match(/\\b\(([^)]+)\)\\b/)?.[1]?.split("|") || [];
2436
matches.forEach(w => result.add(w));
37+
38+
return;
2539
}
2640
});
2741

2842
return Array.from(result);
2943
}
3044

31-
3245
function initKeywordLinker() {
3346
function onDomReady() {
3447
const spans = [
@@ -39,7 +52,13 @@ function initKeywordLinker() {
3952
spans.forEach(span => {
4053
const text = span.textContent;
4154
if (allFunctions.has(text)) {
42-
span.innerHTML = `<a href="/reference/${text}" class="mta-keyword-link">${text}</a>`;
55+
let url = `/reference/${text}`;
56+
const [lib] = text.split(".");
57+
if (["string", "math", "table", "os", "debug", "coroutine"].includes(lib)) {
58+
url = `https://www.lua.org/manual/5.1/manual.html#pdf-${text}`;
59+
}
60+
61+
span.innerHTML = `<a href="${url}" class="mta-keyword-link">${text}</a>`;
4362
}
4463
});
4564
}

0 commit comments

Comments
 (0)