23 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
24 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
37 throw "luaW_type_error returned";
52 lua_createtable(L, 0, 4);
63 c->color_range::~color_range();
74 const bool equal = left == right;
75 lua_pushboolean(L, equal);
98 std::string color_id = luaL_checkstring(L, 2);
106 char const *m = luaL_checkstring(L, 2);
108 if(strcmp(m,
"min") == 0) {
111 if(strcmp(m,
"max") == 0) {
114 if(strcmp(m,
"mid") == 0) {
117 if(strcmp(m,
"minimap") == 0) {
121 if(strcmp(m,
"pango_color") == 0) {
130 static const std::vector<std::string> keys{
"min",
"max",
"mid",
"minimap",
"pango_color"};
137 return luaL_argerror(L, 2,
"color objects canot be modified");
142 std::vector<std::string> all_colours;
144 if(std::all_of(key.begin(), key.end(), [](
char c) {return isdigit(c);})) {
148 all_colours.push_back(key);
157 std::ostringstream cmd_out;
160 cmd_out <<
"Adding color metatable...\n";
164 lua_setfield(L, -2,
"__gc");
166 lua_setfield(L, -2,
"__eq");
168 lua_setfield(L, -2,
"__tostring");
170 lua_setfield(L, -2,
"__index");
172 lua_setfield(L, -2,
"__newindex");
174 lua_setfield(L, -2,
"__dir");
175 lua_pushstring(L,
"color range");
176 lua_setfield(L, -2,
"__metatable");
180 cmd_out <<
"Adding wesnoth.colors table...\n";
182 lua_getglobal(L,
"wesnoth");
183 lua_newuserdatauv(L, 0, 0);
184 lua_createtable(L, 0, 2);
186 lua_setfield(L, -2,
"__index");
188 lua_setfield(L, -2,
"__dir");
189 lua_pushstring(L,
"colors table");
190 lua_setfield(L, -2,
"__metatable");
191 lua_pushboolean(L,
true);
192 lua_setfield(L, -2,
"__dir_tablelike");
193 lua_setmetatable(L, -2);
194 lua_setfield(L, -2,
"colors");
197 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 bool luaW_iscolor(lua_State *L, int index)
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)
int luaW_type_error(lua_State *L, int narg, const char *tname)
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)
The basic class for representing 8-bit RGB or RGBA colour values.