24 #define LOG_LUA LOG_STREAM(info, log_scripting_lua) 25 #define ERR_LUA LOG_STREAM(err, log_scripting_lua) 31 return luaL_testudata(L, index,
colorKey) !=
nullptr;
38 throw "luaW_type_error returned";
40 return *
static_cast<color_range*
>(lua_touserdata(L, index));
53 lua_createtable(L, 0, 4);
64 c->color_range::~color_range();
75 const bool equal = left == right;
76 lua_pushboolean(L, equal);
99 std::string color_id = luaL_checkstring(L, 2);
107 char const *m = luaL_checkstring(L, 2);
109 if(strcmp(m,
"min") == 0) {
112 if(strcmp(m,
"max") == 0) {
115 if(strcmp(m,
"mid") == 0) {
118 if(strcmp(m,
"minimap") == 0) {
122 if(strcmp(m,
"pango_color") == 0) {
131 static const std::vector<std::string> keys{
"min",
"max",
"mid",
"minimap",
"pango_color"};
138 return luaL_argerror(L, 2,
"color objects canot be modified");
143 std::vector<std::string> all_colours;
145 all_colours.push_back(key);
154 std::ostringstream cmd_out;
157 cmd_out <<
"Adding color metatable...\n";
161 lua_setfield(L, -2,
"__gc");
163 lua_setfield(L, -2,
"__eq");
165 lua_setfield(L, -2,
"__tostring");
167 lua_setfield(L, -2,
"__index");
169 lua_setfield(L, -2,
"__newindex");
171 lua_setfield(L, -2,
"__dir");
172 lua_pushstring(L,
"color range");
173 lua_setfield(L, -2,
"__metatable");
177 cmd_out <<
"Adding wesnoth.colors table...\n";
179 lua_getglobal(L,
"wesnoth");
180 lua_newuserdatauv(L, 0, 0);
181 lua_createtable(L, 0, 2);
183 lua_setfield(L, -2,
"__index");
185 lua_setfield(L, -2,
"__dir");
186 lua_pushstring(L,
"colors table");
187 lua_setfield(L, -2,
"__metatable");
188 lua_setmetatable(L, -2);
189 lua_setfield(L, -2,
"colors");
192 return cmd_out.str();
color_t min() const
Minimum color shade.
std::map< std::string, color_range > team_rgb_range
Colors defined by WML [color_range] tags.
static color_range * luaW_pushcolor(lua_State *L, const color_range &color)
int luaW_type_error(lua_State *L, int narg, const char *tname)
static int impl_color_set(lua_State *L)
void lua_push(lua_State *L, const T &val)
static int impl_color_get(lua_State *L)
void luaW_table_set(lua_State *L, int index, std::string_view k, const T &value)
The basic class for representing 8-bit RGB or RGBA colour values.
std::string register_metatables(lua_State *L)
static lg::log_domain log_scripting_lua("scripting/lua")
static int impl_color_tostring(lua_State *L)
Turns a lua color to string.
color_t max() const
Maximum color shade.
static int impl_color_equality(lua_State *L)
Checks two color units for equality.
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
static int impl_color_dir(lua_State *L)
static int impl_color_collect(lua_State *L)
std::string debug() const
Return a string describing the color range for debug output.
color_t rep() const
High-contrast shade, intended for the minimap markers.
const color_range & color_info(const std::string &name)
Standard logging facilities (interface).
static color_range & LuaW_checkcolor(lua_State *L, int index)
static int luaW_pushsinglecolor(lua_State *L, const color_t &color)
static int impl_get_color(lua_State *L)
static int impl_colors_table_dir(lua_State *L)
static const char colorKey[]
static bool luaW_iscolor(lua_State *L, int index)
color_t mid() const
Average color shade.