From 9f4c235dd7eba4f62bce7b271a0e114973babadd Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 25 Dec 2009 01:12:41 +0100 Subject: Trying to wrap Im library inside of the Handle subsystem. --- src/plugin-luaiup.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/plugin-luaiup.cc b/src/plugin-luaiup.cc index 5c53608..c7cf128 100644 --- a/src/plugin-luaiup.cc +++ b/src/plugin-luaiup.cc @@ -1,4 +1,6 @@ #include "BLua.h" +#include "Input.h" +#include "Output.h" #include "iup.h" #include "iuplua.h" #include "iupcontrols.h" @@ -14,6 +16,7 @@ #include #include #include +#include #ifdef FROM_LUAINTERFACE #define NO_DLL @@ -25,6 +28,27 @@ #define WEAK #endif +class imBinFileHandle : public imBinFileBase { + public: + virtual void Open(const char* pFileName) { h = new Input(pFileName); } + virtual void New(const char* pFileName) { h = new Output(pFileName); } + virtual void Close() { delete h; h = 0; } + virtual unsigned long FileSize() { return h->GetSize(); } + virtual int HasError() const { return 0; } + virtual void SeekTo(unsigned long pOffset) { h->seek(pOffset, SEEK_SET); } + virtual void SeekOffset(long pOffset) { h->seek(pOffset, SEEK_CUR); } + virtual void SeekFrom(long pOffset) { h->seek(pOffset, SEEK_SET); } + virtual unsigned long Tell() const { return h->tell(); } + virtual int EndOfFile() const { return h->tell() == h->GetSize(); } + protected: + virtual unsigned long ReadBuf(void* pValues, unsigned long pSize) { return h->read(pValues, pSize); } + virtual unsigned long WriteBuf(void* pValues, unsigned long pSize) { return h->write(pValues, pSize); } + private: + Handle * h; +}; + +static imBinFileBase * imBinFileHandleFunc() { return new imBinFileHandle(); } + static void _init_plugin(Lua * L) { static bool done = false; if (done) return; @@ -38,6 +62,10 @@ static void _init_plugin(Lua * L) { L->wrap_open(imlua_open); L->wrap_open(imlua_open_process); L->wrap_open(cdluaim_open); + + int id = imBinFileRegisterModule(imBinFileHandleFunc); + if (id >= 0) + imBinFileSetCurrentModule(id); } extern "C" { -- cgit v1.2.3