Skip to content

Commit 084f95f

Browse files
committed
first pass
1 parent 0e31897 commit 084f95f

7 files changed

Lines changed: 334 additions & 76 deletions

File tree

deno.jsonc

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
{
22
"tasks": {
33
// build
4-
"build": "deno task keyword-formatted && deno task 'build-*'",
5-
"builddl": "deno task keyword-downloaded && deno task 'build-*'",
6-
"markdown": "deno task keyword-formatted && deno task gen-markdown && cp -R dist docs/html/dist",
7-
"markdowndl": "deno task keyword-downloaded && deno task gen-markdown && cp -R dist docs/html/dist",
4+
"build": {
5+
"dependencies": ["build-lsp","build-selene","build-json","build-vsc"]
6+
},
7+
"markdown": {
8+
"command": "cp -R dist docs/html/dist",
9+
"dependencies": ["gen-markdown"]
10+
},
811
// build steps
9-
"build-lsp" : "deno task 'gen-lsp-*'",
10-
"build-selene": "deno task 'gen-selene-*'",
11-
"build-json" : "deno task 'gen-json-*'",
12-
"build-vsc" : "deno task 'gen-vsc-*'",
12+
"build-lsp" : {
13+
"dependencies": ["gen-lsp-defs","gen-lsp-docs"]
14+
},
15+
"build-selene": {
16+
"dependencies": ["gen-selene-stdlib", "gen-selene-config"]
17+
},
18+
"build-json" : {
19+
"dependencies": ["gen-json-slua", "gen-json-lsl"]
20+
},
21+
"build-vsc" : {
22+
"dependencies": ["gen-vsc-snippets"]
23+
},
1324
// Generate lsp
1425
"gen-lsp-defs": "deno -R -E src/main.ts data/lsl_definitions.yaml slua-defs > dist/ll.d.luau",
1526
"gen-lsp-docs": "deno -R -E src/main.ts data/lsl_definitions.yaml slua-docs > dist/ll.d.json",
@@ -20,15 +31,16 @@
2031
"gen-json-slua" : "deno -R -E src/main.ts data/lsl_definitions.yaml slua-json > dist/slua_keywords.json",
2132
"gen-json-lsl" : "deno -R -E src/main.ts data/lsl_definitions.yaml lsl-json > dist/lsl_keywords.json",
2233
// Build VSC
23-
"gen-vsc-sippets": "deno -R -E src/main.ts data/lsl_definitions.yaml slua-vsc-snippets > dist/slua.code-snippets",
34+
"gen-vsc-snippets": "deno -R -E src/main.ts data/lsl_definitions.yaml slua-vsc-snippets > dist/slua.code-snippets",
2435
// Generate Markdown
2536
"gen-markdown": "deno run -R -W -E src/main.ts ./data/lsl_definitions.yaml slua-markdown docs/output docs/html",
2637
// build and install
2738
"install": "deno task build && deno task copy-to-install",
2839
"copy-to-install": "mkdir -p $HOME/.sl-luau && cp ./dist/* $HOME/.sl-luau/.",
29-
// Keyword manip
30-
"keyword-formatted": "cp data/keywords_lsl_formatted.llsd.xml data/keywords_lsl.llsd.xml",
31-
"keyword-downloaded": "cp data/keywords_lsl_download.llsd.xml data/keywords_lsl.llsd.xml"
40+
"wlf": {
41+
"command": "cp dist/* ../../slua/.types/.",
42+
"dependencies": ["build"]
43+
}
3244
},
3345
"imports": {
3446
"@std/assert": "jsr:@std/assert@1",

src/slua/slua-common.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
NamedVarOpType,
3+
SLua,
34
SLuaBaseType,
45
SLuaClassDef,
56
SLuaCustomType,
@@ -177,11 +178,13 @@ export function isSimpleTypeValue(s: string): s is SLuaSimpleTypeValue {
177178
export function generatePreferedCodeSample(
178179
prefix: string[],
179180
func: SLuaFuncDef,
181+
slua: SLua,
180182
): [string, number] {
181183
let str = generateCodeSample(
182184
prefix,
183185
func,
184186
0,
187+
slua,
185188
0,
186189
func.signatures[0].args.length > 3,
187190
);
@@ -193,6 +196,7 @@ export function generatePreferedCodeSample(
193196
prefix,
194197
func,
195198
i,
199+
slua,
196200
o,
197201
func.signatures[i].args.length > 3,
198202
);
@@ -211,6 +215,7 @@ export function generateCodeSample(
211215
prefix: string[],
212216
func: SLuaFuncDef,
213217
sigIndex: number,
218+
slua: SLua,
214219
off: number = 0,
215220
verbose: boolean = false,
216221
): string {
@@ -221,6 +226,7 @@ export function generateCodeSample(
221226
off,
222227
verbose,
223228
func.takesSelf,
229+
slua,
224230
);
225231
}
226232

@@ -236,8 +242,14 @@ function generateCodeSampleForSig(
236242
off: number = 0,
237243
verbose: boolean = false,
238244
takesSelf: boolean = false,
245+
slua: SLua,
239246
): string {
240-
const [args, funcs] = buildCodeSampleArgsForSig(sig.args, off, verbose);
247+
const [args, funcs] = buildCodeSampleArgsForSig(
248+
sig.args,
249+
off,
250+
verbose,
251+
slua,
252+
);
241253
if (takesSelf) args.shift();
242254
const prefix = funcs.length > 0 ? funcs.join("\n\n") + "\n\n" : "";
243255
if (verbose) {
@@ -251,13 +263,47 @@ function buildCodeSampleArgsForSig(
251263
fargs: SLuaFuncArgs,
252264
off: number,
253265
verbose: boolean = false,
266+
slua: SLua,
254267
): [string[], string[]] {
255268
const args: (string | null)[] = [];
256269
const funcs: string[] = [];
257270
for (const arg of fargs) {
258271
const type = cleanType(arg.type, off);
259272
switch (type.def) {
260-
case "custom":
273+
case "custom": {
274+
const custom = slua.types[type.value];
275+
if (custom) {
276+
let ctype = custom.type;
277+
if (ctype instanceof Array) {
278+
ctype = ctype[0];
279+
}
280+
switch (ctype.def) {
281+
case "simple":
282+
args.push(
283+
buildCodeSampleSimpleArgForSig(ctype, verbose),
284+
);
285+
break;
286+
case "value":
287+
args.push(ctype.value.toString());
288+
break;
289+
case "function":
290+
funcs.push(
291+
generateCodeSampleForFunction(
292+
ctype.value,
293+
arg.name,
294+
),
295+
);
296+
args.push(arg.name);
297+
break;
298+
default:
299+
args.push(type.value.toString());
300+
break;
301+
}
302+
} else {
303+
args.push(type.value.toString());
304+
}
305+
break;
306+
}
261307
case "value":
262308
args.push(type.value.toString());
263309
break;
@@ -318,6 +364,10 @@ function generateCodeSampleForFunction(
318364
if (name) {
319365
result += `local ${name} = `;
320366
}
367+
sig = JSON.parse(JSON.stringify(sig));
368+
for (const arg of sig.args) {
369+
if (!arg.name) arg.name = "arg";
370+
}
321371
return `${result}function(${
322372
mapArgsToFunctionParamString(sig.args, true)
323373
}) : ${mapResultToFunctionString(sig.result)}\n -- Your code\nend`;

src/slua/slua-docs-gen.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
buildSluaJson,
3+
SLua,
34
// SLuaClassDef,
45
SLuaConstDef,
56
SLuaFuncDef,
@@ -57,7 +58,7 @@ export async function buildSluaDocs(
5758
},
5859
};
5960

60-
outputGlobals(data.global.props, docs);
61+
outputGlobals(data.global.props, docs, [], data);
6162
// outputClasses(data.classes, docs);
6263

6364
return docs;
@@ -95,6 +96,7 @@ function outputGlobals(
9596
data: SLuaGlobalTableProps,
9697
docs: Docs,
9798
section: string[] = [],
99+
slua: SLua,
98100
) {
99101
for (const key in data) {
100102
const entry = data[key];
@@ -106,13 +108,18 @@ function outputGlobals(
106108
break;
107109
}
108110
case "func": {
109-
outputFuncDoc(entry as SLuaFuncDef, docs, section);
111+
outputFuncDoc(entry as SLuaFuncDef, docs, section, slua);
110112
break;
111113
}
112114
case "table": {
113115
const table = entry as SLuaGlobalTable;
114116
outputTable(`${section}${table.name}`, docs);
115-
outputGlobals(table.props, docs, [...section, table.name]);
117+
outputGlobals(
118+
table.props,
119+
docs,
120+
[...section, table.name],
121+
slua,
122+
);
116123
break;
117124
}
118125
default:
@@ -129,17 +136,6 @@ function outputTable(name: string, docs: Docs) {
129136
};
130137
}
131138

132-
function outputEventDoc(
133-
event: SLuaEventDef,
134-
docs: Docs,
135-
section: string[] = [],
136-
) {
137-
docs[`${prefix}/global/${[...section, event.name].join(".")}`] = {
138-
documentation: event.desc || "n./a",
139-
learn_more_link: event.link,
140-
};
141-
}
142-
143139
function outputConstDoc(
144140
con: SLuaConstDef,
145141
docs: Docs,
@@ -157,12 +153,16 @@ function outputFuncDoc(
157153
func: SLuaFuncDef,
158154
docs: Docs,
159155
section: string[] = [],
156+
slua: SLua,
160157
) {
161-
docs[
162-
`${prefix}/global/${[...section, func.name].join(".")}`
163-
] = {
158+
const doc: Doc = {
164159
documentation: func.desc || "n./a",
165-
learn_more_link: func.link,
166-
code_sample: generateCodeSample(section, func, 0),
160+
code_sample: generateCodeSample(section, func, 0, slua),
167161
};
162+
if (func.link) {
163+
doc.learn_more_link = func.link;
164+
}
165+
docs[
166+
`${prefix}/global/${[...section, func.name].join(".")}`
167+
] = doc;
168168
}

src/slua/slua-json-gen.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ const newSimpleType = (
157157
const newValueType = (t: string): SLuaValueType => {
158158
return { def: "value", value: t };
159159
};
160+
const newFuncType = (t: SLuaFuncSig): SLuaFunctionType => {
161+
return { def: "function", value: t };
162+
};
160163
const newValueTypeArray = (t: string[]): SLuaValueType[] => {
161164
return t.map(newValueType);
162165
};
@@ -1344,7 +1347,27 @@ function buildSLuaTimersProto(): SLuaClassDef {
13441347
EventHandler,
13451348
[
13461349
newArg("seconds", "interval in seconds", "number"),
1347-
newArg("handler", "handler function", EventHandler),
1350+
newArg(
1351+
"handler",
1352+
"handler function",
1353+
newFuncType(
1354+
newSFuncSignature(
1355+
"()",
1356+
[
1357+
newArg(
1358+
"scheduledTime",
1359+
"The time the timer was meant to fire, see `ll.GetTime`",
1360+
"number",
1361+
),
1362+
newArg(
1363+
"delay",
1364+
"The interval specified for this timer",
1365+
"number",
1366+
),
1367+
],
1368+
),
1369+
),
1370+
),
13481371
],
13491372
),
13501373
],
@@ -1359,7 +1382,22 @@ function buildSLuaTimersProto(): SLuaClassDef {
13591382
EventHandler,
13601383
[
13611384
newArg("seconds", "delay in seconds", "number"),
1362-
newArg("handler", "handler function", EventHandler),
1385+
newArg(
1386+
"handler",
1387+
"handler function",
1388+
newFuncType(
1389+
newSFuncSignature(
1390+
"()",
1391+
[
1392+
newArg(
1393+
"scheduledTime",
1394+
"The time the timer was meant to fire, use `ll.GetTime` to calculate delta",
1395+
"number",
1396+
),
1397+
],
1398+
),
1399+
),
1400+
),
13631401
],
13641402
),
13651403
],

0 commit comments

Comments
 (0)