Procházet zdrojové kódy

Add append methods to QByteArray script bindings

Neal Wilson před 9 roky
rodič
revize
cfb502d234
1 změnil soubory, kde provedl 23 přidání a 0 odebrání
  1. 23
    0
      src/typica.w

+ 23
- 0
src/typica.w Zobrazit soubor

@@ -2082,6 +2082,8 @@ void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine);
2082 2082
 QScriptValue QByteArray_fromHex(QScriptContext *context, QScriptEngine *engine);
2083 2083
 QScriptValue QByteArray_getAt(QScriptContext *context, QScriptEngine *engine);
2084 2084
 QScriptValue QByteArray_setAt(QScriptContext *context, QScriptEngine *engine);
2085
+QScriptValue QByteArray_appendBytes(QScriptContext *context, QScriptEngine *engine);
2086
+QScriptValue QByteArray_appendString(QScriptContext *context, QScriptEngine *engine);
2085 2087
 
2086 2088
 @ First, we provide some functionns for moving array data across the
2087 2089
 language barrier.
@@ -2126,6 +2128,8 @@ void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine)
2126 2128
 	value.setProperty("fromHex", engine->newFunction(QByteArray_fromHex));
2127 2129
 	value.setProperty("getAt", engine->newFunction(QByteArray_getAt));
2128 2130
 	value.setProperty("setAt", engine->newFunction(QByteArray_setAt));
2131
+	value.setProperty("appendBytes", engine->newFunction(QByteArray_appendBytes));
2132
+	value.setProperty("appendString", engine->newFunction(QByteArray_appendString));
2129 2133
 }
2130 2134
 
2131 2135
 @ Perhaps the easiest way to deal with fixed byte strings for serial
@@ -2156,6 +2160,25 @@ QScriptValue QByteArray_setAt(QScriptContext *context, QScriptEngine *)
2156 2160
 	self[argument<int>(0, context)] = (char)(argument<int>(1, context));
2157 2161
 }
2158 2162
 
2163
+@ Methods are provided for appending either another |QByteArray| or a string
2164
+to a |QByteArray|. The only difference between these functions is the expected
2165
+argument type.
2166
+
2167
+@<Functions for scripting@>=
2168
+QScriptValue QByteArray_appendBytes(QScriptContext *context, QScriptEngine *engine)
2169
+{
2170
+	QByteArray self = getself<QByteArray>(context);
2171
+	return engine->toScriptValue<QByteArray>(
2172
+		self.append(argument<QByteArray>(0, context)));
2173
+}
2174
+
2175
+QScriptValue QByteArray_appendString(QScriptContext *context, QScriptEngine *engine)
2176
+{
2177
+	QByteArray self = getself<QByteArray>(context);
2178
+	return engine->toScriptValue<QByteArray>(
2179
+		self.append(argument<QString>(0, context)));
2180
+}
2181
+
2159 2182
 @* Scripting QBuffer.
2160 2183
 
2161 2184
 \noindent Sometimes it is desirable to load a roast profile from a file. At

Loading…
Zrušit
Uložit