Browse Source

Add append methods to QByteArray script bindings

Neal Wilson 10 years ago
parent
commit
cfb502d234
1 changed files with 23 additions and 0 deletions
  1. 23
    0
      src/typica.w

+ 23
- 0
src/typica.w View File

2082
 QScriptValue QByteArray_fromHex(QScriptContext *context, QScriptEngine *engine);
2082
 QScriptValue QByteArray_fromHex(QScriptContext *context, QScriptEngine *engine);
2083
 QScriptValue QByteArray_getAt(QScriptContext *context, QScriptEngine *engine);
2083
 QScriptValue QByteArray_getAt(QScriptContext *context, QScriptEngine *engine);
2084
 QScriptValue QByteArray_setAt(QScriptContext *context, QScriptEngine *engine);
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
 @ First, we provide some functionns for moving array data across the
2088
 @ First, we provide some functionns for moving array data across the
2087
 language barrier.
2089
 language barrier.
2126
 	value.setProperty("fromHex", engine->newFunction(QByteArray_fromHex));
2128
 	value.setProperty("fromHex", engine->newFunction(QByteArray_fromHex));
2127
 	value.setProperty("getAt", engine->newFunction(QByteArray_getAt));
2129
 	value.setProperty("getAt", engine->newFunction(QByteArray_getAt));
2128
 	value.setProperty("setAt", engine->newFunction(QByteArray_setAt));
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
 @ Perhaps the easiest way to deal with fixed byte strings for serial
2135
 @ Perhaps the easiest way to deal with fixed byte strings for serial
2156
 	self[argument<int>(0, context)] = (char)(argument<int>(1, context));
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
 @* Scripting QBuffer.
2182
 @* Scripting QBuffer.
2160
 
2183
 
2161
 \noindent Sometimes it is desirable to load a roast profile from a file. At
2184
 \noindent Sometimes it is desirable to load a roast profile from a file. At

Loading…
Cancel
Save