Browse Source

Getters and setters for bytes in a QByteArray from scripts

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

+ 20
- 0
src/typica.w View File

2080
 QScriptValue constructQByteArray(QScriptContext *context, QScriptEngine *engine);
2080
 QScriptValue constructQByteArray(QScriptContext *context, QScriptEngine *engine);
2081
 void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine);
2081
 void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine);
2082
 QScriptValue QByteArray_fromHex(QScriptContext *context, QScriptEngine *engine);
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
 @ First, we provide some functionns for moving array data across the
2086
 @ First, we provide some functionns for moving array data across the
2085
 language barrier.
2087
 language barrier.
2122
 void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine)
2124
 void setQByteArrayProperties(QScriptValue value, QScriptEngine *engine)
2123
 {
2125
 {
2124
 	value.setProperty("fromHex", engine->newFunction(QByteArray_fromHex));
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
 @ Perhaps the easiest way to deal with fixed byte strings for serial
2131
 @ Perhaps the easiest way to deal with fixed byte strings for serial
2136
 	return engine->toScriptValue<QByteArray>(retval);
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
 @* Scripting QBuffer.
2159
 @* Scripting QBuffer.
2140
 
2160
 
2141
 \noindent Sometimes it is desirable to load a roast profile from a file. At
2161
 \noindent Sometimes it is desirable to load a roast profile from a file. At

Loading…
Cancel
Save