summaryrefslogtreecommitdiff
path: root/src/plugin-luaiup.cc
blob: c7cf12894194d1200e02a6c83ed5ed76a3a3df4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#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 <cd.h>
#include <cdgdiplus.h>
#include <cdlua.h>
#include <cdluaiup.h>
#include "iupluaim.h"
#include <im.h>
#include <im_image.h>
#include <imlua.h>
#include <cdluaim.h>
#include <im_binfile.h>

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