summaryrefslogtreecommitdiff
path: root/library/include
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-08-19 14:27:44 +0400
committerAlexander Gavrilov2012-08-19 14:27:44 +0400
commit30f71ff5106d271d04bfa26b976441cfa9b2abf6 (patch)
treeced0b058f615b90a75c495be1f4db6045100b972 /library/include
parentb8ee52131bccd174f06c9124980bbcb8df7c80e4 (diff)
downloaddfhack-30f71ff5106d271d04bfa26b976441cfa9b2abf6.tar.gz
dfhack-30f71ff5106d271d04bfa26b976441cfa9b2abf6.tar.bz2
dfhack-30f71ff5106d271d04bfa26b976441cfa9b2abf6.tar.xz
Implement support for lua-backed viewscreens.
Diffstat (limited to 'library/include')
-rw-r--r--library/include/LuaTools.h10
-rw-r--r--library/include/modules/Screen.h37
2 files changed, 47 insertions, 0 deletions
diff --git a/library/include/LuaTools.h b/library/include/LuaTools.h
index d3c7a65d..897e7032 100644
--- a/library/include/LuaTools.h
+++ b/library/include/LuaTools.h
@@ -192,6 +192,16 @@ namespace DFHack {namespace Lua {
}
/**
+ * Call through to the function with try/catch for C++ exceptions.
+ */
+ DFHACK_EXPORT int CallWithCatch(lua_State *, int (*fn)(lua_State*), const char *context = NULL);
+
+ template<int (*cb)(lua_State*)>
+ int CallWithCatchWrapper(lua_State *state) {
+ return CallWithCatch(state, cb);
+ }
+
+ /**
* Invoke lua function via pcall. Returns true if success.
* If an error is signalled, and perr is true, it is printed and popped from the stack.
*/
diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h
index 7c5c8ba5..0e4963fb 100644
--- a/library/include/modules/Screen.h
+++ b/library/include/modules/Screen.h
@@ -95,6 +95,12 @@ namespace DFHack
/// Fills a rectangle with one pen. Possibly more efficient than a loop over paintTile.
DFHACK_EXPORT bool fillRect(const Pen &pen, int x1, int y1, int x2, int y2);
+ /// Wipes the screen to full black
+ DFHACK_EXPORT bool clear();
+
+ /// Requests repaint
+ DFHACK_EXPORT bool invalidate();
+
/// Find a loaded graphics tile from graphics raws.
DFHACK_EXPORT bool findGraphicsTile(const std::string &page, int x, int y, int *ptile, int *pgs = NULL);
@@ -111,6 +117,37 @@ namespace DFHack
static bool is_instance(df::viewscreen *screen);
+ virtual bool is_lua_screen() { return false; }
virtual std::string getFocusString() = 0;
};
+
+ class DFHACK_EXPORT dfhack_lua_viewscreen : public dfhack_viewscreen {
+ std::string focus;
+
+ void update_focus(lua_State *L, int idx);
+
+ bool safe_call_lua(int (*pf)(lua_State *), int args, int rvs);
+ static dfhack_lua_viewscreen *get_self(lua_State *L);
+
+ static int do_destroy(lua_State *L);
+ static int do_render(lua_State *L);
+ static int do_notify(lua_State *L);
+ static int do_input(lua_State *L);
+
+ public:
+ dfhack_lua_viewscreen(lua_State *L, int table_idx);
+ virtual ~dfhack_lua_viewscreen();
+
+ static df::viewscreen *get_pointer(lua_State *L, int idx, bool make);
+
+ virtual bool is_lua_screen() { return true; }
+ virtual std::string getFocusString() { return focus; }
+
+ virtual void render();
+ virtual void logic();
+ virtual void help();
+ virtual void resize(int w, int h);
+ virtual void feed(std::set<df::interface_key> *keys);
+ virtual bool key_conflict(df::interface_key key);
+ };
}