summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/LuaHandle.cc142
1 files changed, 136 insertions, 6 deletions
diff --git a/lib/LuaHandle.cc b/lib/LuaHandle.cc
index 568538d..044f427 100644
--- a/lib/LuaHandle.cc
+++ b/lib/LuaHandle.cc
@@ -36,6 +36,11 @@ class sLuaHandle : public Base {
static int readU8(lua_State * L);
static int readU16(lua_State * L);
static int readU32(lua_State * L);
+ static int readU64(lua_State * L);
+ static int read8(lua_State * L);
+ static int read16(lua_State * L);
+ static int read32(lua_State * L);
+ static int read64(lua_State * L);
static int readFloat(lua_State * L);
static int readDouble(lua_State * L);
static int readfile(lua_State * L);
@@ -44,6 +49,11 @@ class sLuaHandle : public Base {
static int writeU8(lua_State * L);
static int writeU16(lua_State * L);
static int writeU32(lua_State * L);
+ static int writeU64(lua_State * L);
+ static int write8(lua_State * L);
+ static int write16(lua_State * L);
+ static int write32(lua_State * L);
+ static int write64(lua_State * L);
static int writeFloat(lua_State * L);
static int writeDouble(lua_State * L);
static int copyfrom(lua_State * L);
@@ -91,7 +101,7 @@ class sLuaHandle : public Base {
static int getcaps(lua_State * L, int);
static int action(lua_State * L, int);
enum {
- U8, U16, U32, R_FLOAT, R_DOUBLE,
+ U8, U16, U32, I8, I16, I32, R_FLOAT, R_DOUBLE,
};
enum {
from, to
@@ -238,15 +248,21 @@ int sLuaHandle::readstring(lua_State * __L) {
Handle * h;
String r;
- if (n != 1) {
+ if ((n < 1) || (n > 2) || ((n == 2) && !L->isnumber(2))) {
L->error("Incorrect arguments to method `Headle::readstring'");
}
- h = L->recast<Handle>();
-
- (*h) >> r;
+ h = L->recast<Handle>(1);
- L->push(r);
+ if (n == 2) {
+ size_t s = L->tonumber(2);
+ char * t = (char *) malloc(s + 1);
+ h->read(t, s);
+ L->push(t, s);
+ } else {
+ (*h) >> r;
+ L->push(r);
+ }
return 1;
}
@@ -355,6 +371,56 @@ int sLuaHandle::readU32(lua_State * L) {
return read(L, U32);
}
+int sLuaHandle::readU64(lua_State * L) {
+ Lua * L = Lua::find(__L);
+ int n = L->gettop();
+ lua_Number r;
+ Handle * h;
+
+ if (n != 1) {
+ L->error("Incorrect arguments to method `Headle::readU64'");
+ }
+
+ h = L->recast<Handle>();
+
+ String r(h->readU64());
+
+ L->push(r);
+
+ return 1;
+}
+
+int sLuaHandle::read8(lua_State * L) {
+ return read(L, I8);
+}
+
+int sLuaHandle::read16(lua_State * L) {
+ return read(L, I16);
+}
+
+int sLuaHandle::read32(lua_State * L) {
+ return read(L, I32);
+}
+
+int sLuaHandle::read64(lua_State * L) {
+ Lua * L = Lua::find(__L);
+ int n = L->gettop();
+ lua_Number r;
+ Handle * h;
+
+ if (n != 1) {
+ L->error("Incorrect arguments to method `Headle::read64'");
+ }
+
+ h = L->recast<Handle>();
+
+ String r(h->read64());
+
+ L->push(r);
+
+ return 1;
+}
+
int sLuaHandle::readFloat(lua_State * L) {
return read(L, R_FLOAT);
}
@@ -438,6 +504,54 @@ int sLuaHandle::writeU32(lua_State * L) {
return write(L, U32);
}
+int sLuaHandle::writeU64(lua_State * L) {
+ Lua * L = Lua::find(__L);
+ int n = L->gettop();
+ lua_Number r;
+ Handle * h;
+
+ if ((n != 2) || !L->isstring(2)) {
+ L->error("Incorrect arguments to method `Headle::writeU64'");
+ }
+
+ h = L->recast<Handle>(1);
+
+ String r = L->tostring(2);
+ h->WriteU64(r.to_Uint64());
+
+ return 0;
+}
+
+int sLuaHandle::write8(lua_State * L) {
+ return write(L, I8);
+}
+
+int sLuaHandle::write16(lua_State * L) {
+ return write(L, I16);
+}
+
+int sLuaHandle::write32(lua_State * L) {
+ return write(L, I32);
+}
+
+int sLuaHandle::write64(lua_State * L) {
+ Lua * L = Lua::find(__L);
+ int n = L->gettop();
+ lua_Number r;
+ Handle * h;
+
+ if ((n != 2) || !L->isstring(2)) {
+ L->error("Incorrect arguments to method `Headle::write64'");
+ }
+
+ h = L->recast<Handle>(1);
+
+ String r = L->tostring(2);
+ h->Write64(r.to_int64());
+
+ return 0;
+}
+
int sLuaHandle::writeFloat(lua_State * L) {
return write(L, R_FLOAT);
}
@@ -462,6 +576,9 @@ int sLuaHandle::read(lua_State * __L, int t) {
case U8: r = h->readU8(); break;
case U16: r = h->readU16(); break;
case U32: r = h->readU32(); break;
+ case I8: r = h->read8(); break;
+ case I16: r = h->read16(); break;
+ case I32: r = h->read32(); break;
case R_FLOAT: r = h->readFloat(); break;
case R_DOUBLE: r = h->readDouble(); break;
}
@@ -488,6 +605,9 @@ int sLuaHandle::write(lua_State * __L, int t) {
case U8: h->writeU8(r); break;
case U16: h->writeU16(r); break;
case U32: h->writeU32(r); break;
+ case I8: h->write8(r); break;
+ case I16: h->write16(r); break;
+ case I32: h->write32(r); break;
case R_FLOAT: h->writeFloat(r); break;
case R_DOUBLE: h->writeDouble(r); break;
}
@@ -1028,11 +1148,21 @@ void LuaHandle::pushmembers(Lua * L) {
pushit(L, "readU8", sLuaHandle::readU8);
pushit(L, "readU16", sLuaHandle::readU16);
pushit(L, "readU32", sLuaHandle::readU32);
+ pushit(L, "readU64", sLuaHandle::readU64);
+ pushit(L, "read8", sLuaHandle::read8);
+ pushit(L, "read16", sLuaHandle::read16);
+ pushit(L, "read32", sLuaHandle::read32);
+ pushit(L, "read64", sLuaHandle::read64);
pushit(L, "readFloat", sLuaHandle::readFloat);
pushit(L, "readDouble", sLuaHandle::readDouble);
pushit(L, "writeU8", sLuaHandle::writeU8);
pushit(L, "writeU16", sLuaHandle::writeU16);
pushit(L, "writeU32", sLuaHandle::writeU32);
+ pushit(L, "writeU64", sLuaHandle::writeU64);
+ pushit(L, "write8", sLuaHandle::write8);
+ pushit(L, "write16", sLuaHandle::write16);
+ pushit(L, "write32", sLuaHandle::write32);
+ pushit(L, "write64", sLuaHandle::write64);
pushit(L, "writeFloat", sLuaHandle::writeFloat);
pushit(L, "writeDouble", sLuaHandle::writeDouble);