| 845 | }; |
| 846 | |
| 847 | static int dfhack_pen_newindex(lua_State *L) |
| 848 | { |
| 849 | lua_settop(L, 3); |
| 850 | luaL_checktype(L, 1, LUA_TUSERDATA); |
| 851 | int id = luaL_checkoption(L, 2, NULL, pen_fields); |
| 852 | int arg = 0; |
| 853 | Pen &pen = *check_pen_native(L, 1); |
| 854 | bool wipe_tile = false, wipe_tc = false; |
| 855 | |
| 856 | switch (id) { |
| 857 | case 0: |
| 858 | if (lua_type(L, 3) != LUA_TNUMBER) |
| 859 | arg = (unsigned char)*luaL_checkstring(L, 3); |
| 860 | else |
| 861 | arg = luaL_checkint(L, 3); |
| 862 | pen.ch = arg; |
| 863 | lua_pushinteger(L, (unsigned char)pen.ch); |
| 864 | break; |
| 865 | case 1: |
| 866 | pen.fg = luaL_checkint(L, 3) & 15; |
| 867 | lua_pushinteger(L, pen.fg); |
| 868 | break; |
| 869 | case 2: |
| 870 | pen.bold = lua_toboolean(L, 3); |
| 871 | lua_pushboolean(L, pen.bold); |
| 872 | break; |
| 873 | case 3: |
| 874 | pen.bg = luaL_checkint(L, 3) & 15; |
| 875 | lua_pushinteger(L, pen.bg); |
| 876 | break; |
| 877 | case 4: |
| 878 | arg = lua_isnil(L, 3) ? 0 : luaL_checkint(L, 3); |
| 879 | if (arg < 0) |
| 880 | luaL_argerror(L, 3, "invalid tile index"); |
| 881 | pen.tile = arg; |
| 882 | if (pen.tile) |
| 883 | lua_pushinteger(L, pen.tile); |
| 884 | else |
| 885 | lua_pushnil(L); |
| 886 | break; |
| 887 | case 5: |
| 888 | wipe_tile = (pen.tile_mode == Pen::TileColor); |
| 889 | pen.tile_mode = lua_toboolean(L, 3) ? Pen::CharColor : Pen::AsIs; |
| 890 | lua_pushboolean(L, pen.tile_mode == Pen::CharColor); |
| 891 | break; |
| 892 | case 6: |
| 893 | if (pen.tile_mode != Pen::TileColor) { wipe_tc = true; pen.tile_bg = 0; } |
| 894 | pen.tile_fg = luaL_checkint(L, 3) & 15; |
| 895 | pen.tile_mode = Pen::TileColor; |
| 896 | lua_pushinteger(L, pen.tile_fg); |
| 897 | break; |
| 898 | case 7: |
| 899 | if (pen.tile_mode != Pen::TileColor) { wipe_tc = true; pen.tile_fg = 7; } |
| 900 | pen.tile_bg = luaL_checkint(L, 3) & 15; |
| 901 | pen.tile_mode = Pen::TileColor; |
| 902 | lua_pushinteger(L, pen.tile_bg); |
| 903 | break; |
| 904 | case 8: |
nothing calls this directly
no test coverage detected