summaryrefslogtreecommitdiff
path: root/iup/srclua5/il_getcolor.c
blob: 4d6cf71b0eb0bd3f4d5ec975262b6b618d6f3f19 (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
/** \file
 * \brief IupGetColor bindig to Lua 5.
 *
 * See Copyright Notice in "iup.h"
 */
 
#include <stdlib.h>

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

#include "iup.h"

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

 
static int GetColor(lua_State *L)
{
  int x = (int)luaL_checknumber(L,1);
  int y = (int)luaL_checknumber(L,2);
  unsigned char r = (unsigned char) luaL_optnumber(L,3,0);
  unsigned char g = (unsigned char) luaL_optnumber(L,4,0);
  unsigned char b = (unsigned char) luaL_optnumber(L,5,0);
  int ret = IupGetColor(x,y,&r,&g,&b);
  if (ret) 
  {
    lua_pushnumber(L, (int) r);
    lua_pushnumber(L, (int) g);
    lua_pushnumber(L, (int) b);
    return 3;
  } 
  else 
  {
    lua_pushnil(L);
    return 1;
  }
}

int iupgclua_open(lua_State * L)
{
  iuplua_register(L, GetColor, "GetColor");
  return 0;
}