File indexing completed on 2025-01-05 05:23:45

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2010, 2011, 2012 Alex Richardson <alex.richardson@gmx.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_SCRIPTENGINEINITIALIZER_HPP
0010 #define KASTEN_SCRIPTENGINEINITIALIZER_HPP
0011 
0012 class QScriptEngine;
0013 class QScriptContext;
0014 class QScriptValue;
0015 
0016 /** This class adds all functions to the scriptengine that are needed for the scripts.
0017  *
0018  * For example this allows developers to write something like.
0019  * @code
0020  * var teststructure = struct({
0021  *      // now the members
0022  *      member1 : uint8(),
0023  *      member2 : array(uint16(),12),
0024  *      member3 : bitfield("bool",1),
0025  *      member4 : bitfield("unsigned", 12),
0026  * })
0027  * @endcode
0028  * @note
0029  */
0030 namespace ScriptEngineInitializer {
0031 
0032 /** @return a new QScriptEngine with the functions added to the global object */
0033 QScriptEngine* newEngine();
0034 /** add the necessary functions to the QScriptEngine */
0035 void addFuctionsToScriptEngine(QScriptEngine* engine);
0036 
0037 namespace Private {
0038 /** create a new enum:
0039  *  first parameter is the type, second parameter is a list of name - value pairs */
0040 QScriptValue scriptNewEnum(QScriptContext* ctx, QScriptEngine* eng);
0041 /** create a new flag value:
0042  *  first parameter is the type, second parameter is a list of name - value pairs */
0043 QScriptValue scriptNewFlags(QScriptContext* ctx, QScriptEngine* eng);
0044 /** this script constructors/initializer takes no parameters */
0045 QScriptValue scriptNewUInt8(QScriptContext* ctx, QScriptEngine* eng);
0046 /** this script constructors/initializer takes no parameters */
0047 QScriptValue scriptNewUInt16(QScriptContext* ctx, QScriptEngine* eng);
0048 /** this script constructors/initializer takes no parameters */
0049 QScriptValue scriptNewUInt32(QScriptContext* ctx, QScriptEngine* eng);
0050 /** this script constructors/initializer takes no parameters */
0051 QScriptValue scriptNewUInt64(QScriptContext* ctx, QScriptEngine* eng);
0052 
0053 /** this script constructors/initializer takes no parameters */
0054 QScriptValue scriptNewInt8(QScriptContext* ctx, QScriptEngine* eng);
0055 /** this script constructors/initializer takes no parameters */
0056 QScriptValue scriptNewInt16(QScriptContext* ctx, QScriptEngine* eng);
0057 /** this script constructors/initializer takes no parameters */
0058 QScriptValue scriptNewInt32(QScriptContext* ctx, QScriptEngine* eng);
0059 /** this script constructors/initializer takes no parameters */
0060 QScriptValue scriptNewInt64(QScriptContext* ctx, QScriptEngine* eng);
0061 
0062 /** this script constructors/initializer takes no parameters */
0063 QScriptValue scriptNewBool8(QScriptContext* ctx, QScriptEngine* eng);
0064 /** this script constructors/initializer takes no parameters */
0065 QScriptValue scriptNewBool16(QScriptContext* ctx, QScriptEngine* eng);
0066 /** this script constructors/initializer takes no parameters */
0067 QScriptValue scriptNewBool32(QScriptContext* ctx, QScriptEngine* eng);
0068 /** this script constructors/initializer takes no parameters */
0069 QScriptValue scriptNewBool64(QScriptContext* ctx, QScriptEngine* eng);
0070 
0071 /** this script constructors/initializer takes no parameters */
0072 QScriptValue scriptNewFloat(QScriptContext* ctx, QScriptEngine* eng);
0073 /** this script constructors/initializer takes no parameters */
0074 QScriptValue scriptNewDouble(QScriptContext* ctx, QScriptEngine* eng);
0075 
0076 /** this script constructors/initializer takes no parameters */
0077 QScriptValue scriptNewChar(QScriptContext* ctx, QScriptEngine* eng);
0078 
0079 /** this script constructor/initializer function takes 2 arguments:
0080  *  <br>
0081  *  -the first is the type of the bitfield: "signed", "bool" or "unsigned"<br>
0082  *  -the second is the width (in bits) of the bitfield)
0083  */
0084 QScriptValue scriptNewBitfield(QScriptContext* ctx, QScriptEngine* eng);
0085 
0086 /** this script constructor/initializer function takes 1 argument and returns a struct object:<br>
0087  * an object (hierarchy), which represents the children.<br>
0088  * An example would be:
0089  * @code
0090  * var obj = struct({
0091  *      member1 : uint8(),
0092  *      member2 : int32(),
0093  *      member3 : union({
0094  *          first : uint32(),
0095  *          second: float(),
0096  *          }),
0097  *      member4 : double(),
0098  *    })
0099  * @endcode
0100  */
0101 QScriptValue scriptNewStruct(QScriptContext* ctx, QScriptEngine* eng);
0102 /** this script constructor/initializer function takes 1 argument and returns a union object:<br>
0103  * an object (hierarchy), which represents the children.<br>
0104  * An example would be:
0105  * @code
0106  * var obj = union({
0107  *      member1 : uint8(),
0108  *      member2 : int32(),
0109  *      member3 : struct({
0110  *          first : uint32(),
0111  *          second: float(),
0112  *          }),
0113  *      member4 : double(),
0114  *    })
0115  * @endcode
0116  */
0117 QScriptValue scriptNewUnion(QScriptContext* ctx, QScriptEngine* eng);
0118 /** this constructor/initializer function takes 2 arguments and returns an array:<br>
0119  *  -the first is an object of the type of the array (can also be a struct or a union or even another array)<br>
0120  *  -the second is the length of the array<br>
0121  */
0122 QScriptValue scriptNewArray(QScriptContext* ctx, QScriptEngine* eng);
0123 /** this constructor takes one argument, the encoding of the string (as a string) */
0124 QScriptValue scriptNewString(QScriptContext* ctx, QScriptEngine* eng);
0125 /** this constructor takes two arguments: 1. type of the pointer and 2. the target type */
0126 QScriptValue scriptNewPointer(QScriptContext* ctx, QScriptEngine* eng);
0127 /** this constructor takes three arguments: 1. initial fields 2. the alternatives 3. (optional) default fields */
0128 QScriptValue scriptNewTaggedUnion(QScriptContext* ctx, QScriptEngine* eng);
0129 
0130 QScriptValue getChild(QScriptContext* ctx, QScriptEngine* eng);
0131 QScriptValue addUpdateFunc(QScriptContext* ctx, QScriptEngine* eng);
0132 QScriptValue addValidationFunc(QScriptContext* ctx, QScriptEngine* eng);
0133 QScriptValue alternativeFunc(QScriptContext* ctx, QScriptEngine* eng);
0134 QScriptValue importScriptFunc(QScriptContext* ctx, QScriptEngine* eng);
0135 
0136 /** this allows you to write e.g.
0137  *  return struct({foo : uint8() })
0138  *      .set({ updateFunc : ...,
0139  *             name : "something"})
0140  *
0141  */
0142 QScriptValue addCustomPropertiesFunc(QScriptContext* ctx, QScriptEngine* eng);
0143 
0144 }
0145 
0146 }
0147 
0148 #endif /* KASTEN_SCRIPTENGINEINITIALIZER_HPP */