#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: 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; 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); } }