mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
add qscript tool
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
bfe1058823
commit
7e200a18ad
20 changed files with 1036 additions and 22 deletions
|
@ -17,5 +17,6 @@ if(NOT KATIE_BOOTSTRAP)
|
|||
endif()
|
||||
add_subdirectory(qhelpgenerator)
|
||||
add_subdirectory(qcollectiongenerator)
|
||||
add_subdirectory(qscript)
|
||||
add_subdirectory(designer)
|
||||
endif()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "LCONVERT 1"
|
||||
.TH LCONVERT 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH LCONVERT 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "LRELEASE 1"
|
||||
.TH LRELEASE 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH LRELEASE 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "LUPDATE 1"
|
||||
.TH LUPDATE 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH LUPDATE 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "MOC 1"
|
||||
.TH MOC 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH MOC 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "QCOLLECTIONGENERATOR 1"
|
||||
.TH QCOLLECTIONGENERATOR 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH QCOLLECTIONGENERATOR 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "QDBUS 1"
|
||||
.TH QDBUS 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH QDBUS 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "QDBUSCPP2XML 1"
|
||||
.TH QDBUSCPP2XML 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH QDBUSCPP2XML 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "QDBUSXML2CPP 1"
|
||||
.TH QDBUSXML2CPP 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH QDBUSXML2CPP 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "QHELPGENERATOR 1"
|
||||
.TH QHELPGENERATOR 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH QHELPGENERATOR 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
43
src/tools/qscript/CMakeLists.txt
Normal file
43
src/tools/qscript/CMakeLists.txt
Normal file
|
@ -0,0 +1,43 @@
|
|||
# add_definitions()
|
||||
set(EXTRA_QTSCRIPT_LIBS KtCore KtScript)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_BINARY_DIR}/include
|
||||
${CMAKE_BINARY_DIR}/privateinclude
|
||||
${CMAKE_BINARY_DIR}/include/QtCore
|
||||
${CMAKE_BINARY_DIR}/privateinclude/QtCore
|
||||
${CMAKE_BINARY_DIR}/include/QtScript
|
||||
${CMAKE_BINARY_DIR}/privateinclude/QtScript
|
||||
)
|
||||
|
||||
set(QSCRIPT_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bytearrayclass.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bytearrayprototype.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/qscript.cpp
|
||||
)
|
||||
|
||||
set(QSCRIPT_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bytearrayclass.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bytearrayprototype.h
|
||||
)
|
||||
|
||||
katie_resources(${QSCRIPT_SOURCES} ${QSCRIPT_HEADERS})
|
||||
katie_setup_flags()
|
||||
|
||||
add_executable(qscript ${QSCRIPT_SOURCES} ${QSCRIPT_HEADERS})
|
||||
target_link_libraries(qscript ${EXTRA_QTSCRIPT_LIBS})
|
||||
|
||||
install(
|
||||
TARGETS qscript
|
||||
EXPORT KatieBinaryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}
|
||||
RUNTIME DESTINATION ${QT_BINARIES_PATH}
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
if(NOT KATIE_PLATFORM MATCHES "(win32|wince|mac)")
|
||||
install(
|
||||
FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/qscript.1
|
||||
DESTINATION ${MAN_INSTALL_PATH}/man1
|
||||
)
|
||||
endif()
|
308
src/tools/qscript/bytearrayclass.cpp
Normal file
308
src/tools/qscript/bytearrayclass.cpp
Normal file
|
@ -0,0 +1,308 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtScript/QScriptClassPropertyIterator>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include "bytearrayclass.h"
|
||||
#include "bytearrayprototype.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
Q_DECLARE_METATYPE(QByteArray*)
|
||||
Q_DECLARE_METATYPE(ByteArrayClass*)
|
||||
|
||||
class ByteArrayClassPropertyIterator : public QScriptClassPropertyIterator
|
||||
{
|
||||
public:
|
||||
ByteArrayClassPropertyIterator(const QScriptValue &object);
|
||||
~ByteArrayClassPropertyIterator();
|
||||
|
||||
bool hasNext() const;
|
||||
void next();
|
||||
|
||||
bool hasPrevious() const;
|
||||
void previous();
|
||||
|
||||
void toFront();
|
||||
void toBack();
|
||||
|
||||
QScriptString name() const;
|
||||
uint id() const;
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
int m_last;
|
||||
};
|
||||
|
||||
//! [0]
|
||||
ByteArrayClass::ByteArrayClass(QScriptEngine *engine)
|
||||
: QObject(engine), QScriptClass(engine)
|
||||
{
|
||||
qScriptRegisterMetaType<QByteArray>(engine, toScriptValue, fromScriptValue);
|
||||
|
||||
length = engine->toStringHandle(QLatin1String("length"));
|
||||
|
||||
proto = engine->newQObject(new ByteArrayPrototype(this),
|
||||
QScriptEngine::QtOwnership,
|
||||
QScriptEngine::SkipMethodsInEnumeration
|
||||
| QScriptEngine::ExcludeSuperClassMethods
|
||||
| QScriptEngine::ExcludeSuperClassProperties);
|
||||
QScriptValue global = engine->globalObject();
|
||||
proto.setPrototype(global.property("Object").property("prototype"));
|
||||
|
||||
ctor = engine->newFunction(construct, proto);
|
||||
ctor.setData(engine->toScriptValue(this));
|
||||
}
|
||||
//! [0]
|
||||
|
||||
ByteArrayClass::~ByteArrayClass()
|
||||
{
|
||||
}
|
||||
|
||||
//! [3]
|
||||
QScriptClass::QueryFlags ByteArrayClass::queryProperty(const QScriptValue &object,
|
||||
const QScriptString &name,
|
||||
QueryFlags flags, uint *id)
|
||||
{
|
||||
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
|
||||
if (!ba)
|
||||
return 0;
|
||||
if (name == length) {
|
||||
return flags;
|
||||
} else {
|
||||
bool isArrayIndex;
|
||||
qint32 pos = name.toArrayIndex(&isArrayIndex);
|
||||
if (!isArrayIndex)
|
||||
return 0;
|
||||
*id = pos;
|
||||
if ((flags & HandlesReadAccess) && (pos >= ba->size()))
|
||||
flags &= ~HandlesReadAccess;
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
QScriptValue ByteArrayClass::property(const QScriptValue &object,
|
||||
const QScriptString &name, uint id)
|
||||
{
|
||||
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
|
||||
if (!ba)
|
||||
return QScriptValue();
|
||||
if (name == length) {
|
||||
return ba->length();
|
||||
} else {
|
||||
qint32 pos = id;
|
||||
if ((pos < 0) || (pos >= ba->size()))
|
||||
return QScriptValue();
|
||||
return uint(ba->at(pos)) & 255;
|
||||
}
|
||||
return QScriptValue();
|
||||
}
|
||||
//! [4]
|
||||
|
||||
//! [5]
|
||||
void ByteArrayClass::setProperty(QScriptValue &object,
|
||||
const QScriptString &name,
|
||||
uint id, const QScriptValue &value)
|
||||
{
|
||||
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
|
||||
if (!ba)
|
||||
return;
|
||||
if (name == length) {
|
||||
resize(*ba, value.toInt32());
|
||||
} else {
|
||||
qint32 pos = id;
|
||||
if (pos < 0)
|
||||
return;
|
||||
if (ba->size() <= pos)
|
||||
resize(*ba, pos + 1);
|
||||
(*ba)[pos] = char(value.toInt32());
|
||||
}
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
QScriptValue::PropertyFlags ByteArrayClass::propertyFlags(
|
||||
const QScriptValue &/*object*/, const QScriptString &name, uint /*id*/)
|
||||
{
|
||||
if (name == length) {
|
||||
return QScriptValue::Undeletable
|
||||
| QScriptValue::SkipInEnumeration;
|
||||
}
|
||||
return QScriptValue::Undeletable;
|
||||
}
|
||||
//! [6]
|
||||
|
||||
//! [7]
|
||||
QScriptClassPropertyIterator *ByteArrayClass::newIterator(const QScriptValue &object)
|
||||
{
|
||||
return new ByteArrayClassPropertyIterator(object);
|
||||
}
|
||||
//! [7]
|
||||
|
||||
QString ByteArrayClass::name() const
|
||||
{
|
||||
return QLatin1String("ByteArray");
|
||||
}
|
||||
|
||||
QScriptValue ByteArrayClass::prototype() const
|
||||
{
|
||||
return proto;
|
||||
}
|
||||
|
||||
QScriptValue ByteArrayClass::constructor()
|
||||
{
|
||||
return ctor;
|
||||
}
|
||||
|
||||
//! [10]
|
||||
QScriptValue ByteArrayClass::newInstance(int size)
|
||||
{
|
||||
engine()->reportAdditionalMemoryCost(size);
|
||||
return newInstance(QByteArray(size, /*ch=*/0));
|
||||
}
|
||||
//! [10]
|
||||
|
||||
//! [1]
|
||||
QScriptValue ByteArrayClass::newInstance(const QByteArray &ba)
|
||||
{
|
||||
QScriptValue data = engine()->newVariant(QVariant::fromValue(ba));
|
||||
return engine()->newObject(this, data);
|
||||
}
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
QScriptValue ByteArrayClass::construct(QScriptContext *ctx, QScriptEngine *)
|
||||
{
|
||||
ByteArrayClass *cls = qscriptvalue_cast<ByteArrayClass*>(ctx->callee().data());
|
||||
if (!cls)
|
||||
return QScriptValue();
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
if (arg.instanceOf(ctx->callee()))
|
||||
return cls->newInstance(qscriptvalue_cast<QByteArray>(arg));
|
||||
int size = arg.toInt32();
|
||||
return cls->newInstance(size);
|
||||
}
|
||||
//! [2]
|
||||
|
||||
QScriptValue ByteArrayClass::toScriptValue(QScriptEngine *eng, const QByteArray &ba)
|
||||
{
|
||||
QScriptValue ctor = eng->globalObject().property("ByteArray");
|
||||
ByteArrayClass *cls = qscriptvalue_cast<ByteArrayClass*>(ctor.data());
|
||||
if (!cls)
|
||||
return eng->newVariant(QVariant::fromValue(ba));
|
||||
return cls->newInstance(ba);
|
||||
}
|
||||
|
||||
void ByteArrayClass::fromScriptValue(const QScriptValue &obj, QByteArray &ba)
|
||||
{
|
||||
ba = qvariant_cast<QByteArray>(obj.data().toVariant());
|
||||
}
|
||||
|
||||
//! [9]
|
||||
void ByteArrayClass::resize(QByteArray &ba, int newSize)
|
||||
{
|
||||
int oldSize = ba.size();
|
||||
ba.resize(newSize);
|
||||
if (newSize > oldSize)
|
||||
engine()->reportAdditionalMemoryCost(newSize - oldSize);
|
||||
}
|
||||
//! [9]
|
||||
|
||||
|
||||
|
||||
ByteArrayClassPropertyIterator::ByteArrayClassPropertyIterator(const QScriptValue &object)
|
||||
: QScriptClassPropertyIterator(object)
|
||||
{
|
||||
toFront();
|
||||
}
|
||||
|
||||
ByteArrayClassPropertyIterator::~ByteArrayClassPropertyIterator()
|
||||
{
|
||||
}
|
||||
|
||||
//! [8]
|
||||
bool ByteArrayClassPropertyIterator::hasNext() const
|
||||
{
|
||||
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object().data());
|
||||
return m_index < ba->size();
|
||||
}
|
||||
|
||||
void ByteArrayClassPropertyIterator::next()
|
||||
{
|
||||
m_last = m_index;
|
||||
++m_index;
|
||||
}
|
||||
|
||||
bool ByteArrayClassPropertyIterator::hasPrevious() const
|
||||
{
|
||||
return (m_index > 0);
|
||||
}
|
||||
|
||||
void ByteArrayClassPropertyIterator::previous()
|
||||
{
|
||||
--m_index;
|
||||
m_last = m_index;
|
||||
}
|
||||
|
||||
void ByteArrayClassPropertyIterator::toFront()
|
||||
{
|
||||
m_index = 0;
|
||||
m_last = -1;
|
||||
}
|
||||
|
||||
void ByteArrayClassPropertyIterator::toBack()
|
||||
{
|
||||
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object().data());
|
||||
m_index = ba->size();
|
||||
m_last = -1;
|
||||
}
|
||||
|
||||
QScriptString ByteArrayClassPropertyIterator::name() const
|
||||
{
|
||||
return object().engine()->toStringHandle(QString::number(m_last));
|
||||
}
|
||||
|
||||
uint ByteArrayClassPropertyIterator::id() const
|
||||
{
|
||||
return m_last;
|
||||
}
|
||||
//! [8]
|
91
src/tools/qscript/bytearrayclass.h
Normal file
91
src/tools/qscript/bytearrayclass.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef BYTEARRAYCLASS_H
|
||||
#define BYTEARRAYCLASS_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtScript/QScriptClass>
|
||||
#include <QtScript/QScriptString>
|
||||
|
||||
class ByteArrayClass : public QObject, public QScriptClass
|
||||
{
|
||||
public:
|
||||
ByteArrayClass(QScriptEngine *engine);
|
||||
~ByteArrayClass();
|
||||
|
||||
QScriptValue constructor();
|
||||
|
||||
QScriptValue newInstance(int size = 0);
|
||||
QScriptValue newInstance(const QByteArray &ba);
|
||||
|
||||
QueryFlags queryProperty(const QScriptValue &object,
|
||||
const QScriptString &name,
|
||||
QueryFlags flags, uint *id);
|
||||
|
||||
QScriptValue property(const QScriptValue &object,
|
||||
const QScriptString &name, uint id);
|
||||
|
||||
void setProperty(QScriptValue &object, const QScriptString &name,
|
||||
uint id, const QScriptValue &value);
|
||||
|
||||
QScriptValue::PropertyFlags propertyFlags(
|
||||
const QScriptValue &object, const QScriptString &name, uint id);
|
||||
|
||||
QScriptClassPropertyIterator *newIterator(const QScriptValue &object);
|
||||
|
||||
QString name() const;
|
||||
|
||||
QScriptValue prototype() const;
|
||||
|
||||
private:
|
||||
static QScriptValue construct(QScriptContext *ctx, QScriptEngine *eng);
|
||||
|
||||
static QScriptValue toScriptValue(QScriptEngine *eng, const QByteArray &ba);
|
||||
static void fromScriptValue(const QScriptValue &obj, QByteArray &ba);
|
||||
|
||||
void resize(QByteArray &ba, int newSize);
|
||||
|
||||
QScriptString length;
|
||||
QScriptValue proto;
|
||||
QScriptValue ctor;
|
||||
};
|
||||
|
||||
#endif
|
137
src/tools/qscript/bytearrayprototype.cpp
Normal file
137
src/tools/qscript/bytearrayprototype.cpp
Normal file
|
@ -0,0 +1,137 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "bytearrayprototype.h"
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
Q_DECLARE_METATYPE(QByteArray*)
|
||||
|
||||
ByteArrayPrototype::ByteArrayPrototype(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
ByteArrayPrototype::~ByteArrayPrototype()
|
||||
{
|
||||
}
|
||||
|
||||
//! [0]
|
||||
QByteArray *ByteArrayPrototype::thisByteArray() const
|
||||
{
|
||||
return qscriptvalue_cast<QByteArray*>(thisObject().data());
|
||||
}
|
||||
//! [0]
|
||||
|
||||
void ByteArrayPrototype::chop(int n)
|
||||
{
|
||||
thisByteArray()->chop(n);
|
||||
}
|
||||
|
||||
bool ByteArrayPrototype::equals(const QByteArray &other)
|
||||
{
|
||||
return *thisByteArray() == other;
|
||||
}
|
||||
|
||||
QByteArray ByteArrayPrototype::left(int len) const
|
||||
{
|
||||
return thisByteArray()->left(len);
|
||||
}
|
||||
|
||||
//! [1]
|
||||
QByteArray ByteArrayPrototype::mid(int pos, int len) const
|
||||
{
|
||||
return thisByteArray()->mid(pos, len);
|
||||
}
|
||||
|
||||
QScriptValue ByteArrayPrototype::remove(int pos, int len)
|
||||
{
|
||||
thisByteArray()->remove(pos, len);
|
||||
return thisObject();
|
||||
}
|
||||
//! [1]
|
||||
|
||||
QByteArray ByteArrayPrototype::right(int len) const
|
||||
{
|
||||
return thisByteArray()->right(len);
|
||||
}
|
||||
|
||||
QByteArray ByteArrayPrototype::simplified() const
|
||||
{
|
||||
return thisByteArray()->simplified();
|
||||
}
|
||||
|
||||
QByteArray ByteArrayPrototype::toBase64() const
|
||||
{
|
||||
return thisByteArray()->toBase64();
|
||||
}
|
||||
|
||||
QByteArray ByteArrayPrototype::toLower() const
|
||||
{
|
||||
return thisByteArray()->toLower();
|
||||
}
|
||||
|
||||
QByteArray ByteArrayPrototype::toUpper() const
|
||||
{
|
||||
return thisByteArray()->toUpper();
|
||||
}
|
||||
|
||||
QByteArray ByteArrayPrototype::trimmed() const
|
||||
{
|
||||
return thisByteArray()->trimmed();
|
||||
}
|
||||
|
||||
void ByteArrayPrototype::truncate(int pos)
|
||||
{
|
||||
thisByteArray()->truncate(pos);
|
||||
}
|
||||
|
||||
QString ByteArrayPrototype::toLatin1String() const
|
||||
{
|
||||
return QString::fromLatin1(*thisByteArray());
|
||||
}
|
||||
|
||||
//! [2]
|
||||
QScriptValue ByteArrayPrototype::valueOf() const
|
||||
{
|
||||
return thisObject().data();
|
||||
}
|
||||
//! [2]
|
||||
|
||||
#include "moc_bytearrayprototype.h"
|
79
src/tools/qscript/bytearrayprototype.h
Normal file
79
src/tools/qscript/bytearrayprototype.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef BYTEARRAYPROTOTYPE_H
|
||||
#define BYTEARRAYPROTOTYPE_H
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtScript/QScriptable>
|
||||
#include <QtScript/QScriptValue>
|
||||
|
||||
//! [0]
|
||||
class ByteArrayPrototype : public QObject, public QScriptable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ByteArrayPrototype(QObject *parent = 0);
|
||||
~ByteArrayPrototype();
|
||||
|
||||
public slots:
|
||||
void chop(int n);
|
||||
bool equals(const QByteArray &other);
|
||||
QByteArray left(int len) const;
|
||||
QByteArray mid(int pos, int len = -1) const;
|
||||
QScriptValue remove(int pos, int len);
|
||||
QByteArray right(int len) const;
|
||||
QByteArray simplified() const;
|
||||
QByteArray toBase64() const;
|
||||
QByteArray toLower() const;
|
||||
QByteArray toUpper() const;
|
||||
QByteArray trimmed() const;
|
||||
void truncate(int pos);
|
||||
QString toLatin1String() const;
|
||||
QScriptValue valueOf() const;
|
||||
|
||||
private:
|
||||
QByteArray *thisByteArray() const;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
|
||||
#endif
|
109
src/tools/qscript/qscript.1
Normal file
109
src/tools/qscript/qscript.1
Normal file
|
@ -0,0 +1,109 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
.de Sp \" Vertical space (when we can't use .PP)
|
||||
.if t .sp .5v
|
||||
.if n .sp
|
||||
..
|
||||
.de Vb \" Begin verbatim text
|
||||
.ft CW
|
||||
.nf
|
||||
.ne \\$1
|
||||
..
|
||||
.de Ve \" End verbatim text
|
||||
.ft R
|
||||
.fi
|
||||
..
|
||||
.\" Set up some character translations and predefined strings. \*(-- will
|
||||
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
|
||||
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
|
||||
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
|
||||
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
|
||||
.\" nothing in troff, for use with C<>.
|
||||
.tr \(*W-
|
||||
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
|
||||
.ie n \{\
|
||||
. ds -- \(*W-
|
||||
. ds PI pi
|
||||
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
|
||||
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
|
||||
. ds L" ""
|
||||
. ds R" ""
|
||||
. ds C` ""
|
||||
. ds C' ""
|
||||
'br\}
|
||||
.el\{\
|
||||
. ds -- \|\(em\|
|
||||
. ds PI \(*p
|
||||
. ds L" ``
|
||||
. ds R" ''
|
||||
. ds C`
|
||||
. ds C'
|
||||
'br\}
|
||||
.\"
|
||||
.\" Escape single quotes in literal strings from groff's Unicode transform.
|
||||
.ie \n(.g .ds Aq \(aq
|
||||
.el .ds Aq '
|
||||
.\"
|
||||
.\" If the F register is turned on, we'll generate index entries on stderr for
|
||||
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
|
||||
.\" entries marked with X<> in POD. Of course, you'll have to process the
|
||||
.\" output yourself in some meaningful fashion.
|
||||
.\"
|
||||
.\" Avoid warning from groff about undefined register 'F'.
|
||||
.de IX
|
||||
..
|
||||
.nr rF 0
|
||||
.if \n(.g .if rF .nr rF 1
|
||||
.if (\n(rF:(\n(.g==0)) \{
|
||||
. if \nF \{
|
||||
. de IX
|
||||
. tm Index:\\$1\t\\n%\t"\\$2"
|
||||
..
|
||||
. if !\nF==2 \{
|
||||
. nr % 0
|
||||
. nr F 2
|
||||
. \}
|
||||
. \}
|
||||
.\}
|
||||
.rr rF
|
||||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "QSCRIPT 1"
|
||||
.TH QSCRIPT 1 "2016-08-03" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
.nh
|
||||
.SH "NAME"
|
||||
qtscript \- stand\-alone Qt scripts interpreter
|
||||
.SH "SYNOPSIS"
|
||||
.IX Header "SYNOPSIS"
|
||||
qtscript [script\-file]
|
||||
.SH "OPTIONS"
|
||||
.IX Header "OPTIONS"
|
||||
.Vb 2
|
||||
\& \-i
|
||||
\& Run interactive.
|
||||
\&
|
||||
\& \-
|
||||
\& Read from standard\-input.
|
||||
.Ve
|
||||
.SH "DESCRIPTION"
|
||||
.IX Header "DESCRIPTION"
|
||||
qtscript can be used as a stand-alone tool to run Qt scripts which could be
|
||||
usefull when testing. Since the scripts are basicly ECMAScript you should see
|
||||
the \s-1ECMA\-262\s0 specification for more details about built-in objects, functions
|
||||
and properties supported.
|
||||
.SH "EXIT STATUS"
|
||||
.IX Header "EXIT STATUS"
|
||||
qtscript returns 0 on success, 1 on wrong usage and other on unexpected
|
||||
failure.
|
||||
.SH "AUTHORS"
|
||||
.IX Header "AUTHORS"
|
||||
The Qt Company Ltd.
|
||||
.PP
|
||||
Copyright (C) 2015 The Qt Company Ltd.
|
||||
.PP
|
||||
Licensed through \s-1GNU\s0 Lesser General Public License/GNU General Public License.
|
211
src/tools/qscript/qscript.cpp
Normal file
211
src/tools/qscript/qscript.cpp
Normal file
|
@ -0,0 +1,211 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the examples of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qscriptengine.h>
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bytearrayclass.h"
|
||||
|
||||
static bool wantsToQuit;
|
||||
|
||||
static QScriptValue qtscript_quit(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(ctx);
|
||||
wantsToQuit = true;
|
||||
return eng->undefinedValue();
|
||||
}
|
||||
|
||||
static void interactive(QScriptEngine *eng)
|
||||
{
|
||||
QScriptValue global = eng->globalObject();
|
||||
QScriptValue quitFunction = eng->newFunction(qtscript_quit);
|
||||
if (!global.property(QLatin1String("exit")).isValid())
|
||||
global.setProperty(QLatin1String("exit"), quitFunction);
|
||||
if (!global.property(QLatin1String("quit")).isValid())
|
||||
global.setProperty(QLatin1String("quit"), quitFunction);
|
||||
wantsToQuit = false;
|
||||
|
||||
QTextStream qin(stdin, QFile::ReadOnly);
|
||||
|
||||
const char *qscript_prompt = "qs> ";
|
||||
const char *dot_prompt = ".... ";
|
||||
const char *prompt = qscript_prompt;
|
||||
|
||||
QString code;
|
||||
|
||||
forever {
|
||||
QString line;
|
||||
|
||||
printf("%s", prompt);
|
||||
fflush(stdout);
|
||||
|
||||
line = qin.readLine();
|
||||
if (line.isNull())
|
||||
break;
|
||||
|
||||
code += line;
|
||||
code += QLatin1Char('\n');
|
||||
|
||||
if (line.trimmed().isEmpty()) {
|
||||
continue;
|
||||
|
||||
} else if (! eng->canEvaluate(code)) {
|
||||
prompt = dot_prompt;
|
||||
|
||||
} else {
|
||||
QScriptValue result = eng->evaluate(code, QLatin1String("typein"));
|
||||
|
||||
code.clear();
|
||||
prompt = qscript_prompt;
|
||||
|
||||
if (! result.isUndefined())
|
||||
fprintf(stderr, "%s\n", qPrintable(result.toString()));
|
||||
|
||||
if (wantsToQuit)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
return engine->importExtension(context->argument(0).toString());
|
||||
}
|
||||
|
||||
static QScriptValue loadScripts(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
for (int i = 0; i < context->argumentCount(); ++i) {
|
||||
QString fileName = context->argument(0).toString();
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return context->throwError(QString::fromLatin1("could not open %0 for reading").arg(fileName));
|
||||
QTextStream ts(&file);
|
||||
QString contents = ts.readAll();
|
||||
file.close();
|
||||
QScriptContext *pc = context->parentContext();
|
||||
context->setActivationObject(pc->activationObject());
|
||||
context->setThisObject(pc->thisObject());
|
||||
QScriptValue ret = engine->evaluate(contents);
|
||||
if (engine->hasUncaughtException())
|
||||
return ret;
|
||||
}
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication *app = new QCoreApplication(argc, argv);
|
||||
QScriptEngine *eng = new QScriptEngine();
|
||||
|
||||
QScriptValue globalObject = eng->globalObject();
|
||||
|
||||
globalObject.setProperty(QLatin1String("load"), eng->newFunction(loadScripts, /*length=*/1));
|
||||
|
||||
{
|
||||
if (!globalObject.property(QLatin1String("qt")).isObject())
|
||||
globalObject.setProperty(QLatin1String("qt"), eng->newObject());
|
||||
QScriptValue qscript = eng->newObject();
|
||||
qscript.setProperty(QLatin1String("importExtension"), eng->newFunction(importExtension));
|
||||
globalObject.property(QLatin1String("qt")).setProperty(QLatin1String("script"), qscript);
|
||||
}
|
||||
|
||||
ByteArrayClass *byteArrayClass = new ByteArrayClass(eng);
|
||||
globalObject.setProperty(QLatin1String("ByteArray"), byteArrayClass->constructor());
|
||||
|
||||
if (! *++argv) {
|
||||
interactive(eng);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
while (const char *arg = *argv++) {
|
||||
QString fn = QString::fromLocal8Bit(arg);
|
||||
|
||||
if (fn == QLatin1String("-i")) {
|
||||
interactive(eng);
|
||||
break;
|
||||
}
|
||||
|
||||
QString contents;
|
||||
int lineNumber = 1;
|
||||
|
||||
if (fn == QLatin1String("-")) {
|
||||
QTextStream stream(stdin, QFile::ReadOnly);
|
||||
contents = stream.readAll();
|
||||
}
|
||||
|
||||
else {
|
||||
QFile file(fn);
|
||||
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QTextStream stream(&file);
|
||||
contents = stream.readAll();
|
||||
file.close();
|
||||
|
||||
// strip off #!/usr/bin/env qscript line
|
||||
if (contents.startsWith(QLatin1String("#!"))) {
|
||||
contents.remove(0, contents.indexOf(QLatin1String("\n")));
|
||||
++lineNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (contents.isEmpty())
|
||||
continue;
|
||||
|
||||
QScriptValue r = eng->evaluate(contents, fn, lineNumber);
|
||||
if (eng->hasUncaughtException()) {
|
||||
QStringList backtrace = eng->uncaughtExceptionBacktrace();
|
||||
fprintf (stderr, " %s\n%s\n\n", qPrintable(r.toString()),
|
||||
qPrintable(backtrace.join(QLatin1String("\n"))));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
delete eng;
|
||||
delete app;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
35
src/tools/qscript/qscript.pod
Normal file
35
src/tools/qscript/qscript.pod
Normal file
|
@ -0,0 +1,35 @@
|
|||
=head1 NAME
|
||||
|
||||
qtscript - stand-alone Qt scripts interpreter
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
qtscript [script-file]
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
-i
|
||||
Run interactive.
|
||||
|
||||
-
|
||||
Read from standard-input.
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
qtscript can be used as a stand-alone tool to run Qt scripts which could be
|
||||
usefull when testing. Since the scripts are basicly ECMAScript you should see
|
||||
the ECMA-262 specification for more details about built-in objects, functions
|
||||
and properties supported.
|
||||
|
||||
=head1 EXIT STATUS
|
||||
|
||||
qtscript returns 0 on success, 1 on wrong usage and other on unexpected
|
||||
failure.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
The Qt Company Ltd.
|
||||
|
||||
Copyright (C) 2015 The Qt Company Ltd.
|
||||
|
||||
Licensed through GNU Lesser General Public License/GNU General Public License.
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "RCC 1"
|
||||
.TH RCC 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH RCC 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
|
||||
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
|
||||
.\"
|
||||
.\" Standard preamble:
|
||||
.\" ========================================================================
|
||||
|
@ -71,7 +71,7 @@
|
|||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "UIC 1"
|
||||
.TH UIC 1 "2016-07-06" "Katie 4.9.0" "Katie Manual"
|
||||
.TH UIC 1 "2016-08-01" "Katie 4.9.0" "Katie Manual"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
|
|
Loading…
Add table
Reference in a new issue