Scripting: qet.apiSignatures(), the calls a script can make

Read from the meta-object, so the list is the one the running build has:
for someone writing a script, and for an assistant that has to write one
without the source at hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-02 09:04:06 +13:00
parent 1c1f9db3eb
commit b7ce89944e
3 changed files with 59 additions and 0 deletions
+34
View File
@@ -122,6 +122,40 @@ int QetScriptApi::folioCount() const
folio, and the first one stands in for it so a script written for the
editor can still be tried headless; -1 if the project has none.
*/
/**
@brief QetScriptApi::apiSignatures
Every call a script can make, as "returnType name(type param, ...)",
read from the meta-object rather than written out by hand, so the list
is the one this build has and cannot drift from it: for a person
writing a script, and for an assistant that has to write one without
the source at hand. A call with default arguments is listed once, with
all of them.
*/
QStringList QetScriptApi::apiSignatures() const
{
QStringList list;
const QMetaObject *meta = metaObject();
for (int i = meta->methodOffset(); i < meta->methodCount(); ++i) {
const QMetaMethod method = meta->method(i);
if (method.methodType() != QMetaMethod::Method
|| method.access() != QMetaMethod::Public
|| (method.attributes() & QMetaMethod::Cloned)) {
continue;
}
const QList<QByteArray> types = method.parameterTypes();
const QList<QByteArray> names = method.parameterNames();
QStringList params;
for (int p = 0; p < types.size(); ++p) {
params << QString::fromLatin1(types.at(p) + ' ' + names.value(p));
}
list << QStringLiteral("%1 %2(%3)")
.arg(QString::fromLatin1(method.typeName()),
QString::fromLatin1(method.name()),
params.join(QStringLiteral(", ")));
}
return list;
}
int QetScriptApi::currentFolio() const
{
if (!m_project) return -1;
+3
View File
@@ -579,6 +579,9 @@ class QetScriptApi : public QObject
// -- logging: a script has no console of its own --
Q_INVOKABLE void log(const QString &message);
// -- what a script can call, read from this class itself --
Q_INVOKABLE QStringList apiSignatures() const;
void setUndoGrouped(bool grouped);
private: