23 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
24 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
43 lua_createtable(L, 0, 4);
54 c->color_range::~color_range();
65 const bool equal = left == right;
66 lua_pushboolean(L, equal);
89 std::string color_id = luaL_checkstring(L, 2);
97 char const *m = luaL_checkstring(L, 2);
99 if(strcmp(m,
"min") == 0) {
102 if(strcmp(m,
"max") == 0) {
105 if(strcmp(m,
"mid") == 0) {
108 if(strcmp(m,
"minimap") == 0) {
112 if(strcmp(m,
"pango_color") == 0) {
121 static const std::vector<std::string>
keys{
"min",
"max",
"mid",
"minimap",
"pango_color"};
128 return luaL_argerror(L, 2,
"color objects canot be modified");
133 std::vector<std::string> all_colours;
135 if(std::all_of(key.begin(), key.end(), [](
char c) {return isdigit(c);})) {
139 all_colours.push_back(key);
148 std::ostringstream cmd_out;
151 cmd_out <<
"Adding color metatable...\n";
155 lua_setfield(L, -2,
"__gc");
157 lua_setfield(L, -2,
"__eq");
159 lua_setfield(L, -2,
"__tostring");
161 lua_setfield(L, -2,
"__index");
163 lua_setfield(L, -2,
"__newindex");
165 lua_setfield(L, -2,
"__dir");
166 lua_pushstring(L,
"color range");
167 lua_setfield(L, -2,
"__metatable");
171 cmd_out <<
"Adding wesnoth.colors table...\n";
173 lua_getglobal(L,
"wesnoth");
174 lua_newuserdatauv(L, 0, 0);
175 lua_createtable(L, 0, 2);
177 lua_setfield(L, -2,
"__index");
179 lua_setfield(L, -2,
"__dir");
180 lua_pushstring(L,
"colors table");
181 lua_setfield(L, -2,
"__metatable");
182 lua_pushboolean(L,
true);
183 lua_setfield(L, -2,
"__dir_tablelike");
184 lua_setmetatable(L, -2);
185 lua_setfield(L, -2,
"colors");
188 return cmd_out.str();
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
Standard logging facilities (interface).
static int impl_color_set(lua_State *L)
static int impl_color_tostring(lua_State *L)
Turns a lua color to string.
static lg::log_domain log_scripting_lua("scripting/lua")
static int impl_color_equality(lua_State *L)
Checks two color units for equality.
static int luaW_pushsinglecolor(lua_State *L, const color_t &color)
static int impl_color_get(lua_State *L)
static int impl_color_dir(lua_State *L)
static color_range * luaW_pushcolor(lua_State *L, const color_range &color)
static int impl_colors_table_dir(lua_State *L)
static color_range & LuaW_checkcolor(lua_State *L, int index)
static int impl_get_color(lua_State *L)
static const char colorKey[]
static int impl_color_collect(lua_State *L)
std::map< std::string, color_range, std::less<> > team_rgb_range
Colors defined by WML [color_range] tags.
const color_range & color_info(std::string_view name)
std::string register_metatables(lua_State *L)
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void lua_push(lua_State *L, const T &val)
void luaW_table_set(lua_State *L, int index, std::string_view k, const T &value)
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
The basic class for representing 8-bit RGB or RGBA colour values.