diff options
| author | Alexander Gavrilov | 2012-08-21 11:35:39 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-08-21 11:35:39 +0400 |
| commit | 451e965936c8e3fb911366abe40f2753772acfc2 (patch) | |
| tree | 2a0330da7b43ae8d4e33a8cca109c2e677706f55 /library/LuaApi.cpp | |
| parent | be7bce1541665909283769d1847e6793c4715df3 (diff) | |
| download | dfhack-451e965936c8e3fb911366abe40f2753772acfc2.tar.gz dfhack-451e965936c8e3fb911366abe40f2753772acfc2.tar.bz2 dfhack-451e965936c8e3fb911366abe40f2753772acfc2.tar.xz | |
Add a Painter class for lua viewscreens, and extract other utilities.
Painter clips to an arbitrary rectangle window, and
tracks current cursor and color state.
Diffstat (limited to 'library/LuaApi.cpp')
| -rw-r--r-- | library/LuaApi.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index b8c1248b..7f18ce3e 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -194,16 +194,28 @@ static bool get_int_field(lua_State *L, T *pf, int idx, const char *name, int de return !nil; } +static bool get_char_field(lua_State *L, char *pf, int idx, const char *name, char defval) +{ + lua_getfield(L, idx, name); + + if (lua_type(L, -1) == LUA_TSTRING) + { + *pf = lua_tostring(L, -1)[0]; + lua_pop(L, 1); + return true; + } + else + { + lua_pop(L, 1); + return get_int_field(L, pf, idx, name, defval); + } +} + static void decode_pen(lua_State *L, Pen &pen, int idx) { idx = lua_absindex(L, idx); - lua_getfield(L, idx, "ch"); - if (lua_isstring(L, -1)) - pen.ch = lua_tostring(L, -1)[0]; - else - get_int_field(L, &pen.ch, idx, "ch", 0); - lua_pop(L, 1); + get_char_field(L, &pen.ch, idx, "ch", 0); get_int_field(L, &pen.fg, idx, "fg", 7); get_int_field(L, &pen.bg, idx, "bg", 0); @@ -1104,7 +1116,12 @@ static int screen_paintTile(lua_State *L) int x = luaL_checkint(L, 2); int y = luaL_checkint(L, 3); if (lua_gettop(L) >= 4 && !lua_isnil(L, 4)) - pen.ch = luaL_checkint(L, 4); + { + if (lua_type(L, 4) == LUA_TSTRING) + pen.ch = lua_tostring(L, 4)[0]; + else + pen.ch = luaL_checkint(L, 4); + } if (lua_gettop(L) >= 5 && !lua_isnil(L, 5)) pen.tile = luaL_checkint(L, 5); lua_pushboolean(L, Screen::paintTile(pen, x, y)); |
