diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin-luaiup.cc | 28 |
1 files changed, 28 insertions, 0 deletions
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 <im_image.h> #include <imlua.h> #include <cdluaim.h> +#include <im_binfile.h> #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" { |