Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/ts/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export let start = function () {
luaLibrary.scan();
luaLibrary.parse();

// temporary solution: ignore Page3.ChooseModsWindow lua class
Object.entries(luaLibrary.classes).forEach(([key, cls]) => {
if (!cls.name) {
console.log('Error: ', cls.file.file);
delete luaLibrary.classes[key]
}
})

// Loading all entries
const classes: any[] = Object.values(luaLibrary.classes);
const tables: any[] = Object.values(luaLibrary.tables);
Expand Down
10 changes: 10 additions & 0 deletions src/ts/lua/LuaClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export class LuaClass extends LuaContainer {
const { name } = this;
let documentation: string;

if (!this.name) {
return ``
}

const model = library.getClassModel(this as any);
documentation = this.generateDocumentation(prefix, model);

Expand Down Expand Up @@ -134,6 +138,9 @@ export class LuaClass extends LuaContainer {
generateAPI(prefix: string): string {
const { library } = this.file;
let { name } = this;
if (!name) {
return `// Wrong: class name is undefined`
}

// Render the class documentation. (If present)
const model = library.getClassModel(this as any);
Expand All @@ -147,6 +154,9 @@ export class LuaClass extends LuaContainer {

generateLuaInterface(prefix: string = '', requireFrom: string = ''): string {
const { name } = this;
if (!name) {
return `-- Wrong: class name is undefined`
}
const requireStatement = requireFrom ? `require('${requireFrom}');` : ''
return `${prefix}Exports.${sanitizeName(name)} = loadstring("${requireStatement}return _G['${name}']")()\n`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ts/lua/model/ModelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ILLEGAL_NAMES = [
* @returns The sanitized name.
*/
export const sanitizeName = (name: string): string => {
if (ILLEGAL_NAMES.indexOf(name.toLowerCase()) !== -1) return `_${name}_`;
if (ILLEGAL_NAMES.indexOf((name || '').toLowerCase()) !== -1) return `_${name}_`;
return name;
};

Expand Down