summaryrefslogtreecommitdiff
path: root/iup/srclua5/iuplua_im.c
blob: b700e1a1b8dc17075487d1ee5e552fa5c4cc9e5c (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
/** \file
 * \brief IULUA core - Bindig of iup to Lua 5.
 *
 * See Copyright Notice in "iup.h"
 */
 
#include "iup.h"
#include "iupim.h"

#include <lua.h>
#include <lauxlib.h>

#include "iuplua.h"
#include "iupluaim.h"
#include "il.h"

static int SaveImage(lua_State *L)
{
  Ihandle *image = iuplua_checkihandle(L,1);
  const char *filename = luaL_checkstring(L, 2);
  const char *format = luaL_checkstring(L, 3);
  lua_pushboolean(L, IupSaveImage(image, filename, format));
  return 1;
}

static int LoadImage(lua_State *L)
{
  const char *filename = luaL_checkstring(L, 1);
  Ihandle* image = IupLoadImage(filename);
  iuplua_plugstate(L, image);
  iuplua_pushihandle(L, image);
  return 1;
}

int iupimlua_open(lua_State *L)
{
  iuplua_changeEnv(L);
  iuplua_register(L, LoadImage, "LoadImage");
  iuplua_register(L, SaveImage, "SaveImage");
  iuplua_returnEnv(L);
  return 0; /* nothing in stack */
}

/* obligatory to use require"iupluaim" */
int luaopen_iupluaim(lua_State* L)
{
  return iupimlua_open(L);
}

/* obligatory to use require"iupluaim51" */
int luaopen_iupluaim51(lua_State* L)
{
  return iupimlua_open(L);
}