summaryrefslogtreecommitdiff
path: root/iup/srclua3/il_cells.c
blob: 92969f8b308242ddcc74aead116d21cea8f845e9 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/** \file
 * \brief Bindig of IupCells to Lua 3.
 * @author André Luiz Clinio.
 *
 * See Copyright Notice in "iup.h"
 */
 
#include <stdlib.h>

#include "iup.h"
#include "iupcontrols.h"

#include <lua.h>

#include "iuplua.h"

#include "il.h"
#include "il_controls.h"


static int luacells_mouseclick_cb( Ihandle* handle, int b, int m, 
                                   int i, int j, int x, int y, char* r )
{
  iuplua_call_start(handle, "mouseclick");
  lua_pushnumber(b);
  lua_pushnumber(m);
  lua_pushnumber(i);
  lua_pushnumber(j);
  lua_pushnumber(x);
  lua_pushnumber(y);
  lua_pushstring(r);
  return iuplua_call();
}

static int luacells_mousemotion_cb( Ihandle* handle, int i, int j, 
                                    int x, int y, char* r )
{
  iuplua_call_start(handle, "mousemotion");
  lua_pushnumber(i);
  lua_pushnumber(j);
  lua_pushnumber(x);
  lua_pushnumber(y);
  lua_pushstring(r);
  return iuplua_call();
}

static int luacells_width_cb( Ihandle* handle, int col )
{
  iuplua_call_start(handle, "width");
  lua_pushnumber(col);
  return iuplua_call();
}

static int luacells_height_cb( Ihandle* handle, int line )
{
  iuplua_call_start(handle, "height");
  lua_pushnumber(line);
  return iuplua_call();
}

static int luacells_nlines_cb( Ihandle* handle )
{
  iuplua_call_start(handle, "nlines");
  return iuplua_call();
}

static int luacells_ncols_cb( Ihandle* handle )
{
  iuplua_call_start(handle, "ncols");
  return iuplua_call();
}

static int luacells_hspan_cb( Ihandle* handle, int i, int j )
{
  iuplua_call_start(handle, "hspan");
  lua_pushnumber(i);
  lua_pushnumber(j);
  return iuplua_call();
}

static int luacells_vspan_cb( Ihandle* handle, int i, int j )
{
  iuplua_call_start(handle, "vspan");
  lua_pushnumber(i);
  lua_pushnumber(j);
  return iuplua_call();
}

static int luacells_scrolling_cb( Ihandle* handle, int fline, int fcol )
{
  iuplua_call_start(handle, "scrolling");
  lua_pushnumber(fline);
  lua_pushnumber(fcol);
  return iuplua_call();
}

static void createCells(void) 
{
  int tag = (int)lua_getnumber(lua_getglobal("iuplua_tag"));
  lua_pushusertag(IupCells(), tag);
}

int cellslua_open(void) 
{
  int i;
  struct TypeAssocList {
    char *name; 
    lua_CFunction func; 
  } assoc_list [] = {
    {"iup_cells_mouseclick_cb", (lua_CFunction) luacells_mouseclick_cb },
    {"iup_cells_mousemotion_cb", (lua_CFunction) luacells_mousemotion_cb },
    {"iup_cells_width_cb", (lua_CFunction) luacells_width_cb },
    {"iup_cells_height_cb", (lua_CFunction) luacells_height_cb },
    {"iup_cells_nlines_cb", (lua_CFunction) luacells_nlines_cb },
    {"iup_cells_ncols_cb", (lua_CFunction) luacells_ncols_cb },
    {"iup_cells_hspan_cb", (lua_CFunction) luacells_hspan_cb },
    {"iup_cells_vspan_cb", (lua_CFunction) luacells_vspan_cb },
    {"iup_cells_scrolling_cb", (lua_CFunction) luacells_scrolling_cb }
  };
  int assoc_list_size = (sizeof(assoc_list)/sizeof(struct TypeAssocList));

  lua_register("iupCreateCells", createCells);

  for( i = 0; i < assoc_list_size; i++ )
    lua_register(assoc_list[i].name, assoc_list[i].func);

#ifdef IUPLUA_USELOH
#ifdef TEC_BIGENDIAN
#ifdef TEC_64
#include "loh/cells_be64.loh"
#else
#include "loh/cells_be32.loh"
#endif  
#else
#ifdef TEC_64
#ifdef WIN64
#include "loh/cells_le64w.loh"
#else
#include "loh/cells_le64.loh"
#endif  
#else
#include "loh/cells.loh"
#endif  
#endif  
#else
  iuplua_dofile("luacells.lua");
#endif

  return 1;
}