naev 0.11.5
nlua_colour.c File Reference

Handles colours. More...

#include "nlua_colour.h"
#include "log.h"
#include "nluadef.h"

Go to the source code of this file.

Functions

static int colL_eq (lua_State *L)
 Compares two colours to see if they are the same.
 
static int colL_tostring (lua_State *L)
 Converts a colour to a string.
 
static int colL_new (lua_State *L)
 Gets a colour.
 
static int colL_alpha (lua_State *L)
 Gets the alpha of a colour.
 
static int colL_rgb (lua_State *L)
 Gets the RGB values of a colour.
 
static int colL_hsv (lua_State *L)
 Gets the HSV values of a colour.
 
static int colL_setrgb (lua_State *L)
 Sets the colours values from the RGB colourspace.
 
static int colL_sethsv (lua_State *L)
 Sets the colours values from the HSV colourspace.
 
static int colL_setalpha (lua_State *L)
 Sets the alpha of a colour.
 
static int colL_linearToGamma (lua_State *L)
 Converts a colour from linear to gamma corrected.
 
static int colL_gammaToLinear (lua_State *L)
 Converts a colour from gamma corrected to linear.
 
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 * luaL_checkcolour (lua_State *L, int ind)
 Gets colour at index or raises error if there is no colour at index.
 
glColour * lua_pushcolour (lua_State *L, glColour colour)
 Pushes a colour on the stack.
 
int lua_iscolour (lua_State *L, int ind)
 Checks to see if ind is a colour.
 

Variables

static const luaL_Reg colL_methods []
 

Detailed Description

Handles colours.

Definition in file nlua_colour.c.

Function Documentation

◆ colL_alpha()

static int colL_alpha ( lua_State * L)
static

Gets the alpha of a colour.

Value is from from 0. (transparent) to 1. (opaque).

Lua usage parameter: colour_alpha = col:alpha()

Lua function parameter: Colour col Colour to get alpha of. Lua return parameter: number The alpha of the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: alpha

Definition at line 228 of file nlua_colour.c.

◆ colL_eq()

static int colL_eq ( lua_State * L)
static

Compares two colours to see if they are the same.

Lua function parameter: Colour c1 Colour 1 to compare. Lua function parameter: Colour c2 Colour 2 to compare. Lua return parameter: boolean true if both colours are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 144 of file nlua_colour.c.

◆ colL_gammaToLinear()

static int colL_gammaToLinear ( lua_State * L)
static

Converts a colour from gamma corrected to linear.

Lua function parameter: Colour col Colour to change from gamma corrected to linear. Lua return parameter: Colour Modified colour.

Definition at line 388 of file nlua_colour.c.

◆ colL_hsv()

static int colL_hsv ( lua_State * L)
static

Gets the HSV values of a colour.

Values are from 0. to 1.

Lua usage parameter: h,s,v = col:rgb()

Lua function parameter: Colour col Colour to get HSV values of. Lua function parameter:[opt=false] boolean gamma Whether or not to get the gamma-corrected value or not. Lua return parameter: number The hue of the colour. Lua return parameter: number The saturation of the colour. Lua return parameter: number The value of the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: hsv

Definition at line 279 of file nlua_colour.c.

◆ colL_linearToGamma()

static int colL_linearToGamma ( lua_State * L)
static

Converts a colour from linear to gamma corrected.

Lua function parameter: Colour col Colour to change from linear to gamma. Lua return parameter: Colour Modified colour.

Definition at line 370 of file nlua_colour.c.

◆ colL_new()

static int colL_new ( lua_State * L)
static

Gets a colour.

Lua usage parameter: colour.new( "Red" ) – Gets colour by name Lua usage parameter: colour.new( "Red", 0.5 ) – Gets colour by name with alpha 0.5 Lua usage parameter: colour.new() – Creates a white (blank) colour Lua usage parameter: colour.new( 1., 0., 0. ) – Creates a bright red colour Lua usage parameter: colour.new( 1., 0., 0., 0.5 ) – Creates a bright red colour with alpha 0.5

Lua function parameter: number r Red value of the colour. Lua function parameter: number g Green value of the colour. Lua function parameter: number b Blue value of the colour. Lua function parameter:[opt=1.] number a Alpha value of the colour. Lua return parameter: Colour A newly created colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 185 of file nlua_colour.c.

◆ colL_rgb()

static int colL_rgb ( lua_State * L)
static

Gets the RGB values of a colour.

Values are from 0. to 1.

Lua usage parameter: r,g,b = col:rgb()

Lua function parameter: Colour col Colour to get RGB values of. Lua function parameter:[opt=false] boolean gamma Whether or not to get the gamma-corrected value or not. Lua return parameter: number The red value of the colour. Lua return parameter: number The green value of the colour. Lua return parameter: number The blue value of the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: rgb

Definition at line 249 of file nlua_colour.c.

◆ colL_setalpha()

static int colL_setalpha ( lua_State * L)
static

Sets the alpha of a colour.

Value is from 0. (transparent) to 1. (opaque).

Lua usage parameter: col:setAlpha( 0.5 ) – Make colour half transparent

Lua function parameter: Colour col Colour to set alpha of. Lua function parameter: number alpha Alpha value to set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setAlpha

Definition at line 357 of file nlua_colour.c.

◆ colL_sethsv()

static int colL_sethsv ( lua_State * L)
static

Sets the colours values from the HSV colourspace.

Values are from 0. to 1.

Lua usage parameter: col:setHSV( h, s, v )

Lua function parameter: Colour col Colour to set HSV values. Lua function parameter: number h Hue value to set. Lua function parameter: number s Saturation value to set. Lua function parameter: number v Value to set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setHSV

Definition at line 335 of file nlua_colour.c.

◆ colL_setrgb()

static int colL_setrgb ( lua_State * L)
static

Sets the colours values from the RGB colourspace.

Values are from 0. to 1.

Lua usage parameter: col:setRGB( r, g, b )

Lua function parameter: Colour col Colour to set RGB values. Lua function parameter: number r Red value to set. Lua function parameter: number g Green value to set. Lua function parameter: number b Blue value to set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setRGB

Definition at line 313 of file nlua_colour.c.

◆ colL_tostring()

static int colL_tostring ( lua_State * L)
static

Converts a colour to a string.

Lua function parameter: Colour col Colour to get string from. Lua return parameter: string A string representing the colour.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __tostring

Definition at line 160 of file nlua_colour.c.

◆ lua_iscolour()

int lua_iscolour ( lua_State * L,
int ind )

Checks to see if ind is a colour.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a colour.

Definition at line 120 of file nlua_colour.c.

◆ lua_pushcolour()

glColour * lua_pushcolour ( lua_State * L,
glColour colour )

Pushes a colour on the stack.

Parameters
LLua state to push colour into.
colourColour to push.
Returns
Newly pushed colour.

Definition at line 105 of file nlua_colour.c.

◆ lua_tocolour()

glColour * lua_tocolour ( lua_State * L,
int ind )

Lua bindings to interact with colours.

An example would be:

col1 = colour.new( "Red" ) -- Get by name
col2 = colour.new( 0.5, 0.5, 0.5, 0.3 ) -- Create with RGB values
col3 = colour.new() -- White by default
col2:setHSV( col1:hsv() ) -- Set colour 2 with colour 1's HSV values

Lua module: colour

Gets colour at index.

Parameters
LLua state to get colour from.
indIndex position to find the colour.
Returns
Colour found at the index in the state.

Definition at line 80 of file nlua_colour.c.

◆ luaL_checkcolour()

glColour * luaL_checkcolour ( lua_State * L,
int ind )

Gets colour at index or raises error if there is no colour at index.

Parameters
LLua state to get colour from.
indIndex position to find colour.
Returns
Colour found at the index in the state.

Definition at line 91 of file nlua_colour.c.

◆ nlua_loadCol()

int nlua_loadCol ( nlua_env env)

Loads the colour library.

Parameters
envEnvironment to load colour library into.
Returns
0 on success.

Definition at line 54 of file nlua_colour.c.

Variable Documentation

◆ colL_methods

const luaL_Reg colL_methods[]
static
Initial value:
= {
{ "__eq", colL_eq },
{ "__tostring", colL_tostring },
{ "new", colL_new },
{ "alpha", colL_alpha },
{ "rgb", colL_rgb },
{ "hsv", colL_hsv },
{ "setRGB", colL_setrgb },
{ "setHSV", colL_sethsv },
{ "setAlpha", colL_setalpha },
{ "linearToGamma", colL_linearToGamma },
{ "gammaToLinear", colL_gammaToLinear },
{0,0}
}
static int colL_new(lua_State *L)
Gets 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.
static int colL_tostring(lua_State *L)
Converts a colour to a string.
static int colL_sethsv(lua_State *L)
Sets the colours values from the HSV colourspace.
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.

Colour metatable methods.

Definition at line 33 of file nlua_colour.c.