| 681 | } |
| 682 | |
| 683 | static int adjust_pen(lua_State *L, bool no_copy) |
| 684 | { |
| 685 | lua_settop(L, 4); |
| 686 | |
| 687 | Pen pen; |
| 688 | int iidx = 1; |
| 689 | Lua::CheckPen(L, &pen, 1, true, true); |
| 690 | |
| 691 | if (!lua_isnil(L, 2) || !lua_isnil(L, 3) || !lua_isnil(L, 4)) |
| 692 | { |
| 693 | if (lua_isnumber(L, 2) || lua_isnil(L, 2)) |
| 694 | { |
| 695 | if (!pen.valid()) |
| 696 | pen = Pen(); |
| 697 | |
| 698 | iidx = -1; |
| 699 | |
| 700 | pen.fg = luaL_optint(L, 2, pen.fg) & 15; |
| 701 | pen.bg = luaL_optint(L, 3, pen.bg); |
| 702 | |
| 703 | if (!lua_isnil(L, 4)) |
| 704 | pen.bold = lua_toboolean(L, 4); |
| 705 | else if (!lua_isnil(L, 2)) |
| 706 | { |
| 707 | pen.bold = !!(pen.fg & 8); |
| 708 | pen.fg &= 7; |
| 709 | } |
| 710 | } |
| 711 | else |
| 712 | { |
| 713 | iidx = 2; |
| 714 | Lua::CheckPen(L, &pen, 2, false, false); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | if (no_copy && iidx > 0 && lua_isuserdata(L, iidx)) |
| 719 | lua_pushvalue(L, iidx); |
| 720 | else |
| 721 | Lua::Push(L, pen); |
| 722 | |
| 723 | return 1; |
| 724 | } |
| 725 | |
| 726 | static int dfhack_pen_parse(lua_State *L) |
| 727 | { |
no test coverage detected