Skip to content

Commit 52013b1

Browse files
committed
move class types to be output as classes
1 parent f2aadc6 commit 52013b1

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

deno.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"tasks": {
3+
"all": {
4+
"dependencies": ["build", "markdown"]
5+
},
36
// build
47
"build": {
58
"dependencies": ["build-lsp","build-selene","build-json","build-vsc","build-builtins"]

src/slua/slua-defs-gen.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ export async function buildSluaTypeDefs(
3232
"\n" +
3333
outputTypeDefs(data.types) +
3434
"\n\n" +
35+
outpufClassDefs(
36+
Object.values(data.types).reduce((clsDefs, typeDef) => {
37+
if (typeDef.type instanceof Array) return clsDefs;
38+
if (typeDef.type.def != "class") return clsDefs;
39+
clsDefs[typeDef.name] = typeDef.type.value;
40+
return clsDefs;
41+
}, {}),
42+
) +
43+
"\n\n" +
3544
outpufClassDefs(data.classes) +
3645
"\n\n" +
3746
outputFunctionDefs(data.global.props);
@@ -58,7 +67,12 @@ function outpufClassDefs(classes: StrObj<SLuaClassDef>): string {
5867
for (const fkey in cls.funcs) {
5968
const func = cls.funcs[fkey];
6069
for (const result of func.signatures) {
61-
const args = result.args.map(mapArgToFunctionString);
70+
const self: string[] = func.takesSelf ? ["self"] : [];
71+
const args = [
72+
...self,
73+
...(func.takesSelf ? result.args.slice(1) : result.args)
74+
.map(mapArgToFunctionString),
75+
];
6276
output += ` function ${func.name}(${args.join(", ")}): ${
6377
mapResultToFunctionString(result.result)
6478
}`;
@@ -86,7 +100,7 @@ function outputTypeDefs(typeDefs: StrObj<SLuaTypeDef>): string {
86100
break;
87101
case "class":
88102
if (typeArray) throw `Cannot output type class array`;
89-
typeStrs.push(outputClassType(typ));
103+
// typeStrs.push(outpufClassDefs({[def.name]:typ.value}));//(outputClassType(typ));
90104
break;
91105
case "table":
92106
typeStrs.push(outputTableType(typ));
@@ -105,7 +119,9 @@ function outputTypeDefs(typeDefs: StrObj<SLuaTypeDef>): string {
105119
// } else {
106120

107121
// }
108-
output.push(`type ${def.name} = ` + typeStrs.join("|"));
122+
if (typeStrs.length) {
123+
output.push(`type ${def.name} = ` + typeStrs.join("|"));
124+
}
109125
}
110126
return output.join("\n") + "\n";
111127
}

0 commit comments

Comments
 (0)