Browse Source

Methods for obtaining data as a QByteArray from QIODevice classes in scripts

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

+ 33
- 0
src/typica.w View File

1872
 QScriptValue QIODevice_putChar(QScriptContext *context, QScriptEngine *engine);
1872
 QScriptValue QIODevice_putChar(QScriptContext *context, QScriptEngine *engine);
1873
 QScriptValue QIODevice_writeString(QScriptContext *context, QScriptEngine *engine);
1873
 QScriptValue QIODevice_writeString(QScriptContext *context, QScriptEngine *engine);
1874
 QScriptValue QIODevice_writeBytes(QScriptContext *context, QScriptEngine *engine);
1874
 QScriptValue QIODevice_writeBytes(QScriptContext *context, QScriptEngine *engine);
1875
+QScriptValue QIODevice_readBytes(QScriptContext *context, QScriptEngine *engine);
1876
+QScriptValue QIODevice_peek(QScriptContext *context, QScriptEngine *engine);
1877
+QScriptValue QIODevice_read(QScriptContext *context, QScriptEngine *engine);
1875
 
1878
 
1876
 @ This function is passed to the scripting engine.
1879
 @ This function is passed to the scripting engine.
1877
 
1880
 
1926
 	value.setProperty("putChar", engine->newFunction(QIODevice_putChar));
1929
 	value.setProperty("putChar", engine->newFunction(QIODevice_putChar));
1927
 	value.setProperty("writeString", engine->newFunction(QIODevice_writeString));
1930
 	value.setProperty("writeString", engine->newFunction(QIODevice_writeString));
1928
 	value.setProperty("writeBytes", engine->newFunction(QIODevice_writeBytes));
1931
 	value.setProperty("writeBytes", engine->newFunction(QIODevice_writeBytes));
1932
+	value.setProperty("readBytes", engine->newFunction(QIODevice_readBytes));
1933
+	value.setProperty("peek", engine->newFunction(QIODevice_peek));
1934
+	value.setProperty("read", engine->newFunction(QIODevice_read));
1929
 }
1935
 }
1930
 
1936
 
1931
 @ These are simple wrappers. In the case of the |open()| property, one argument
1937
 @ These are simple wrappers. In the case of the |open()| property, one argument
2038
 	return QScriptValue();
2044
 	return QScriptValue();
2039
 }
2045
 }
2040
 
2046
 
2047
+@ The readBytes method is an alternate wrapper around |QByteArray::readAll()|
2048
+which returns the |QByteArray| instead of converting this to a |QString|.
2049
+
2050
+@<Functions for scripting@>=
2051
+QScriptValue QIODevice_readBytes(QScriptContext *context, QScriptEngine *engine)
2052
+{
2053
+	QIODevice *self = getself<QIODevice *>(context);
2054
+	return QScriptValue(engine->toScriptValue<QByteArray>(self->readAll()));
2055
+}
2056
+
2057
+@ Wrappers around |peek()| and |read()| are also provided.
2058
+
2059
+@<Functions for scripting@>=
2060
+QScriptValue QIODevice_peek(QScriptContext *context, QScriptEngine *engine)
2061
+{
2062
+	QIODevice *self = getself<QIODevice *>(context);
2063
+	return QScriptValue(engine->toScriptValue<QByteArray>(
2064
+		self->peek(argument<int>(0, context))));
2065
+}
2066
+
2067
+QScriptValue QIODevice_read(QScriptContext *context, QScriptEngine *engine)
2068
+{
2069
+	QIODevice *self = getself<QIODevice *>(context);
2070
+	return QScriptValue(engine->toScriptValue<QByteArray>(
2071
+		self->read(argument<int>(0, context))));
2072
+}
2073
+
2041
 @ In order to work with |QByteArray| this should also be exposed to the host
2074
 @ In order to work with |QByteArray| this should also be exposed to the host
2042
 environment.
2075
 environment.
2043
 
2076
 

Loading…
Cancel
Save