Maniascript API generator
Parse the maniascript documentation file generated by the game executable (game.exe /generatescriptdoc=maniascript.h) and generate an object describing the maniascript API.
Install with npm: npm install @maniascript/api.
The package exposes a generate-api command.
``
Usage: generate-api [options]
Generate a typescript or json api file from a maniascript documentation file
Options:
--in
--out
--format
--help Display help
`
Example: generate-api --format json --in path/to/input/maniascript.h --out path/to/output/maniascript.json
import { api } from '@maniascript/api'
api is an object describing Trackmania and Maniaplanet maniascript api.
`ts`
{
trackmania: {
classNames: [
"CMlScript",
"CManiaApp",
"CEditorMainPlugin",
"CServerPlugin",
"CSmMode",
"CSmAction",
"CSmMapType",
"CNod",
...
],
namespaceNames: [
"TextLib",
"MathLib",
...
],
classes: {
CMlScript: {
rawDocumentation: '/! \brief: Brief description\nLong description\n\param _paramName : parameter description\n/',
documentation: {
brief: 'Brief description',
description: 'Long description',
params: [{
name: '_paramName',
description: 'parameter description'
}]
},
enums: {
LinkType: {
rawDocumentation: '/! Raw documentation string /',
documentation: {
brief: '',
description: 'Raw documentation string',
params: []
},
values: [
"ExternalBrowser",
...
]
}
},
variables: {
Page: {
rawDocumentation: '/! Raw documentation string /',
documentation: {
brief: '',
description: 'Raw documentation string',
params: []
},
isConst: true,
type: {
category: "class",
name: "CMlPage"
}
},
...
},
functions: {
IsKeyPressed: [
{
rawDocumentation: '/! Raw documentation string /',
documentation: {
brief: '',
description: 'Raw documentation string',
params: []
},
type: {
category: "literal",
name: "Boolean"
},
parameters: [
{
type: {
category: "literal",
name: "Integer"
},
name: "KeyCode"
}
]
}
],
...
}
},
...
},
namespaces: {
MathLib: {
enums: { ... },
variables: { ... },
functions: { ... }
},
...
}
},
maniaplanet: { ... }
}
* classNames contains the name of all classes listed in the classes object.namespaceNames
* contains the name of all namespaces listed in the namespaces object.classes
* contains the description of each of this classes.namespaces
* contains the description of all the default maniascript libraries. eg: MathLib, TextLib, ...
import { parse, generateFromParseResult, generateFromInput, generateFromFile } from '@maniascript/api'
There are three functions that take different kinds of input and return an an object describing the api.
* generateFromParseResult generate the api from the result of the parse() function.generateFromInput
* generate the api from a text input.generateFromFile
* generate the api from a path to a maniascript documentation file.
`tsmaniascript.h
const result = parse('Content of a documentation file')maniascript.h
const apiFromParseResult = generateFromParseResult(result)
const apiFromInput = generateFromInput('Content of a documentation file')`
const apiFromFile = await generateFromFile('./path/to/maniascript.h')
import { execute } from '@maniascript/api' or const { execute } = require('@maniascript/api')
execute is a function that takes the path to the maniascript documentation file to parse and create a file containing the description of the api defined in the documentation in json format.
`ts`
await execute('path/to/maniascript.h')
// generate a file: 'path/to/maniascript.json'
Optionally, execute can take a path to the file where the api will be generated and a format for the output.
`ts``
await execute('path/to/maniascript.h', 'path/to/api.ts', 'ts')
// or
await execute('path/to/maniascript.h', 'path/to/api.json', 'json')