#include "BLua.h" #include "Input.h" #include "Output.h" #include "iup.h" #include "iuplua.h" #include "iupcontrols.h" #include "iupluacontrols.h" #include "iup_pplot.h" #include "iuplua_pplot.h" #include #include #include #include #include "iupluaim.h" #include #include #include #include #include #ifdef FROM_LUAINTERFACE #define NO_DLL #endif #ifndef WIN32 #define WEAK __attribute__ ((weak)) #else #define WEAK #endif class imBinFileHandle : public imBinFileBase { public: imBinFileHandle() : h(NULL), hasError(0) {} virtual int HasError() const { return hasError; } virtual void Open(const char* pFileName) { try { h = new Input(pFileName); } catch (...) { hasError = 1; } } virtual void New(const char* pFileName) { try { h = new Output(pFileName); } catch (...) { hasError = 1; } } virtual void Close() { try { delete h; h = 0; } catch (...) { hasError = 1; } } virtual unsigned long FileSize() { unsigned long r = 0; try { r = h->GetSize(); } catch (...) { hasError = 1; } return r; } virtual void SeekTo(unsigned long pOffset) { try { h->seek(pOffset, SEEK_SET); } catch (...) { hasError = 1; } } virtual void SeekOffset(long pOffset) { try { h->seek(pOffset, SEEK_CUR); } catch (...) { hasError = 1; } } virtual void SeekFrom(long pOffset) { try { h->seek(pOffset, SEEK_END); } catch (...) { hasError = 1; } } virtual unsigned long Tell() const { unsigned long r = 0; try { r = h->tell(); } catch (...) { hasError = 1; } return r; } virtual int EndOfFile() const { int r = 0; try { r = h->tell() == h->GetSize(); } catch (...) { hasError = 1; } return r; } protected: virtual unsigned long ReadBuf(void* pValues, unsigned long pSize) { unsigned long r = 0; try { r = h->read(pValues, pSize); } catch (...) { hasError = 1; } return r; } virtual unsigned long WriteBuf(void* pValues, unsigned long pSize) { unsigned long r = 0; try { r = h->write(pValues, pSize); } catch (...) { hasError = 1; } return r; } private: Handle * h; mutable int hasError; }; static imBinFileBase * imBinFileHandleFunc() { return new imBinFileHandle(); } static void _init_plugin(Lua * L) { static bool done = false; if (done) return; done = true; L->wrap_open(iuplua_open); L->wrap_open(iupkey_open); L->wrap_open(iupcontrolslua_open); L->wrap_open(cdlua_open); L->wrap_open(cdluaiup_open); L->wrap_open(iupimlua_open); 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" { #ifndef NO_DLL WEAK void init_plugin(Lua * L) { _init_plugin(L); } #endif void luaiup_init(Lua * L) { _init_plugin(L); } }