summaryrefslogtreecommitdiff
path: root/src/LuaHandle.cc
diff options
context:
space:
mode:
authorNicolas Noble <pixel@nobis-crew.org>2013-08-07 16:32:26 -0700
committerNicolas Noble <pixel@nobis-crew.org>2013-08-07 16:32:40 -0700
commitdf00882195da3fb970782f21d79a0a10e6b186b3 (patch)
treef6626a204b464d02768a006a10d465620af59cb6 /src/LuaHandle.cc
parent7f841bd54b8628420b4bec129fae86472b5dc565 (diff)
Adding readU16, readU32 and readU64. The Lua version of readU64 will need GMP support.
Diffstat (limited to 'src/LuaHandle.cc')
-rw-r--r--src/LuaHandle.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/LuaHandle.cc b/src/LuaHandle.cc
index 355b992..6b8bd18 100644
--- a/src/LuaHandle.cc
+++ b/src/LuaHandle.cc
@@ -9,11 +9,15 @@ typedef IOHandle IOInput;
enum IOHandle_methods_t {
IOHANDLE_CLOSE,
IOHANDLE_READU8,
+ IOHANDLE_READU16,
+ IOHANDLE_READU32,
};
struct Balau::lua_functypes_t IOHandle_methods[] = {
{ IOHANDLE_CLOSE, "close", 0, 0, { } },
{ IOHANDLE_READU8, "readU8", 0, 0, { } },
+ { IOHANDLE_READU16, "readU16", 0, 0, { } },
+ { IOHANDLE_READU32, "readU32", 0, 0, { } },
{ -1, 0, 0, 0, 0 },
};
@@ -35,6 +39,18 @@ int sLua_IOHandle::IOHandle_proceed(Balau::Lua & L, int n, IOHandle * obj, int c
return L.yield(Balau::Future<int>([L, c]() mutable { L.push((lua_Number) c.get()); return 1; }));
}
break;
+ case IOHANDLE_READU16:
+ {
+ Balau::Future<uint16_t> c = h->readU16();
+ return L.yield(Balau::Future<int>([L, c]() mutable { L.push((lua_Number) c.get()); return 1; }));
+ }
+ break;
+ case IOHANDLE_READU32:
+ {
+ Balau::Future<uint32_t> c = h->readU32();
+ return L.yield(Balau::Future<int>([L, c]() mutable { L.push((lua_Number) c.get()); return 1; }));
+ }
+ break;
}
return r;
@@ -51,6 +67,8 @@ void Balau::LuaHandleFactory::pushObjectAndMembers(Lua & L) {
PUSH_METHOD(IOHandle, IOHANDLE_CLOSE);
PUSH_METHOD(IOHandle, IOHANDLE_READU8);
+ PUSH_METHOD(IOHandle, IOHANDLE_READU16);
+ PUSH_METHOD(IOHandle, IOHANDLE_READU32);
}