Kaynağa Gözat

Getters and setters for bytes in a QByteArray from scripts

Neal Wilson 9 yıl önce
ebeveyn
işleme
f02cda1f26
1 değiştirilmiş dosya ile 20 ekleme ve 0 silme
  1. 20
    0
      src/typica.w

+ 20
- 0
src/typica.w Dosyayı Görüntüle

@@ -2080,6 +2080,8 @@ void QByteArray_fromScriptValue(const QScriptValue &value, QByteArray &bytes);
2080 2080
 QScriptValue constructQByteArray(QScriptContext *context, QScriptEngine *engine);
2081 2081
 void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine);
2082 2082
 QScriptValue QByteArray_fromHex(QScriptContext *context, QScriptEngine *engine);
2083
+QScriptValue QByteArray_getAt(QScriptContext *context, QScriptEngine *engine);
2084
+QScriptValue QByteArray_setAt(QScriptContext *context, QScriptEngine *engine);
2083 2085
 
2084 2086
 @ First, we provide some functionns for moving array data across the
2085 2087
 language barrier.
@@ -2122,6 +2124,8 @@ want to have wrappers around. These should be added as required.
2122 2124
 void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine)
2123 2125
 {
2124 2126
 	value.setProperty("fromHex", engine->newFunction(QByteArray_fromHex));
2127
+	value.setProperty("getAt", engine->newFunction(QByteArray_getAt));
2128
+	value.setProperty("setAt", engine->newFunction(QByteArray_setAt));
2125 2129
 }
2126 2130
 
2127 2131
 @ Perhaps the easiest way to deal with fixed byte strings for serial
@@ -2136,6 +2140,22 @@ QScriptValue QByteArray_fromHex(QScriptContext *context, QScriptEngine *engine)
2136 2140
 	return engine->toScriptValue<QByteArray>(retval);
2137 2141
 }
2138 2142
 
2143
+@ A pair of methods is provided for getting and setting values at a particular
2144
+byte.
2145
+
2146
+@<Functions for scripting@>=
2147
+QScriptValue QByteArray_getAt(QScriptContext *context, QScriptEngine *)
2148
+{
2149
+	QByteArray self = getself<QByteArray>(context);
2150
+	return QScriptValue((int)(self.at(argument<int>(0, context))));
2151
+}
2152
+
2153
+QScriptValue QByteArray_setAt(QScriptContext *context, QScriptEngine *)
2154
+{
2155
+	QByteArray self = getself<QByteArray>(context);
2156
+	self[argument<int>(0, context)] = (char)(argument<int>(1, context));
2157
+}
2158
+
2139 2159
 @* Scripting QBuffer.
2140 2160
 
2141 2161
 \noindent Sometimes it is desirable to load a roast profile from a file. At

Loading…
İptal
Kaydet