16#include "nlua_colour.h"
22static int colL_eq( lua_State *L );
80 return (glColour*) lua_touserdata(L,ind);
93 luaL_typerror(L, ind, COL_METATABLE);
105 glColour *
c = (glColour*) lua_newuserdata(L,
sizeof(glColour));
107 luaL_getmetatable(L, COL_METATABLE);
108 lua_setmetatable(L, -2);
122 if (lua_getmetatable(L,ind)==0)
124 lua_getfield(L, LUA_REGISTRYINDEX, COL_METATABLE);
127 if (lua_rawequal(L, -1, -2))
147 lua_pushboolean( L, (memcmp( c1, c2,
sizeof(glColour) )==0) );
170 const glColour *col2;
173 if (lua_gettop(L)==0) {
174 col.r = col.g = col.b = col.a = 1.;
176 else if (lua_isnumber(L,1)) {
177 col.r = gammaToLinear(luaL_checknumber(L,1));
178 col.g = gammaToLinear(luaL_checknumber(L,2));
179 col.b = gammaToLinear(luaL_checknumber(L,3));
180 col.a = luaL_optnumber(L,4,1.);
182 else if (lua_isstring(L,1)) {
183 col2 = col_fromName( lua_tostring(L,1) );
185 NLUA_ERROR( L, _(
"Colour '%s' does not exist!"), lua_tostring(L,1) );
189 col.a = luaL_optnumber(L,2,1.);
194 NLUA_INVALID_PARAMETER(L);
214 lua_pushnumber( L, col->a );
235 if (lua_toboolean(L,2)) {
236 lua_pushnumber( L, linearToGamma( col->r ) );
237 lua_pushnumber( L, linearToGamma( col->g ) );
238 lua_pushnumber( L, linearToGamma( col->b ) );
241 lua_pushnumber( L, col->r );
242 lua_pushnumber( L, col->g );
243 lua_pushnumber( L, col->b );
264 float h, s, v, r, g,
b;
266 if (lua_toboolean(L,2)) {
267 r = linearToGamma( col->r );
268 g = linearToGamma( col->g );
269 b = linearToGamma( col->b );
277 lua_pushnumber( L, h );
278 lua_pushnumber( L, s );
279 lua_pushnumber( L, v );
299 col->r = luaL_checknumber(L,2);
300 col->g = luaL_checknumber(L,3);
301 col->b = luaL_checknumber(L,4);
322 h = luaL_checknumber(L,2);
323 s = luaL_checknumber(L,3);
324 v = luaL_checknumber(L,4);
343 col->a = luaL_checknumber(L,2);
357 out.r = linearToGamma( col->r );
358 out.g = linearToGamma( col->g );
359 out.b = linearToGamma( col->b );
375 out.r = gammaToLinear( col->r );
376 out.g = gammaToLinear( col->g );
377 out.b = gammaToLinear( col->b );
void col_rgb2hsv(float *H, float *S, float *V, float R, float G, float B)
Changes colour space from RGB to HSV.
void col_hsv2rgb(glColour *c, float h, float s, float v)
Changes colour space from HSV to RGB.
Header file with generic functions and naev-specifics.
static int colL_new(lua_State *L)
Gets a colour.
int lua_iscolour(lua_State *L, int ind)
Checks to see if ind is a colour.
static int colL_rgb(lua_State *L)
Gets the RGB values of a colour.
static int colL_setrgb(lua_State *L)
Sets the colours values from the RGB colourspace.
static int colL_eq(lua_State *L)
Compares two colours to see if they are the same.
static int colL_hsv(lua_State *L)
Gets the HSV values of a colour.
int nlua_loadCol(nlua_env env)
Loads the colour library.
glColour * lua_tocolour(lua_State *L, int ind)
Lua bindings to interact with colours.
glColour * lua_pushcolour(lua_State *L, glColour colour)
Pushes a colour on the stack.
static int colL_sethsv(lua_State *L)
Sets the colours values from the HSV colourspace.
glColour * luaL_checkcolour(lua_State *L, int ind)
Gets colour at index or raises error if there is no colour at index.
static const luaL_Reg colL_methods[]
static int colL_linearToGamma(lua_State *L)
Converts a colour from linear to gamma corrected.
static int colL_setalpha(lua_State *L)
Sets the alpha of a colour.
static int colL_gammaToLinear(lua_State *L)
Converts a colour from gamma corrected to linear.
static int colL_alpha(lua_State *L)
Gets the alpha of a colour.