| 3831 | return false; |
| 3832 | } |
| 3833 | static inline uint32 gui_getcolour_wrapped(lua_State *L, int offset, bool hasDefaultValue, uint32 defaultColour) { |
| 3834 | switch (lua_type(L,offset)) { |
| 3835 | case LUA_TSTRING: |
| 3836 | { |
| 3837 | const char *str = lua_tostring(L,offset); |
| 3838 | uint32 colour; |
| 3839 | |
| 3840 | if (str2colour(&colour, L, str)) |
| 3841 | return colour; |
| 3842 | else { |
| 3843 | if (hasDefaultValue) |
| 3844 | return defaultColour; |
| 3845 | else |
| 3846 | return luaL_error(L, "unknown colour %s", str); |
| 3847 | } |
| 3848 | } |
| 3849 | case LUA_TNUMBER: |
| 3850 | { |
| 3851 | const char *str = lua_tostring(L,offset); |
| 3852 | return (uint32)strtod(str,NULL); |
| 3853 | } |
| 3854 | case LUA_TTABLE: |
| 3855 | { |
| 3856 | int color = 0xFF; |
| 3857 | lua_pushnil(L); // first key |
| 3858 | int keyIndex = lua_gettop(L); |
| 3859 | int valueIndex = keyIndex + 1; |
| 3860 | while(lua_next(L, offset)) |
| 3861 | { |
| 3862 | bool keyIsString = (lua_type(L, keyIndex) == LUA_TSTRING); |
| 3863 | bool keyIsNumber = (lua_type(L, keyIndex) == LUA_TNUMBER); |
| 3864 | int key = keyIsString ? tolower(*lua_tostring(L, keyIndex)) : (keyIsNumber ? lua_tointeger(L, keyIndex) : 0); |
| 3865 | int value = lua_tointeger(L, valueIndex); |
| 3866 | if(value < 0) value = 0; |
| 3867 | if(value > 255) value = 255; |
| 3868 | switch(key) |
| 3869 | { |
| 3870 | case 1: case 'r': color |= value << 24; break; |
| 3871 | case 2: case 'g': color |= value << 16; break; |
| 3872 | case 3: case 'b': color |= value << 8; break; |
| 3873 | case 4: case 'a': color = (color & ~0xFF) | value; break; |
| 3874 | } |
| 3875 | lua_pop(L, 1); |
| 3876 | } |
| 3877 | return color; |
| 3878 | } break; |
| 3879 | case LUA_TFUNCTION: |
| 3880 | luaL_error(L, "invalid colour"); // NYI |
| 3881 | return 0; |
| 3882 | default: |
| 3883 | if (hasDefaultValue) |
| 3884 | return defaultColour; |
| 3885 | else |
| 3886 | return luaL_error(L, "invalid colour"); |
| 3887 | } |
| 3888 | } |
| 3889 | static uint32 gui_getcolour(lua_State *L, int offset) { |
| 3890 | uint32 colour; |
no test coverage detected