summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/cluautil.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-21 10:26:44 +0200
committerRobert Vollmert <rvollmert@gmx.net>2009-10-21 10:54:13 +0200
commitfccc2460c9eb17ecb89cd02e9fac580a32ec794b (patch)
tree87e6bf8a924fd69147c1f86641a9b730cea392c3 /crawl-ref/source/cluautil.cc
parent6b4885b07d0a5228d7dc20cbbb210a1a168bc8da (diff)
downloadcrawl-ref-fccc2460c9eb17ecb89cd02e9fac580a32ec794b.tar.gz
crawl-ref-fccc2460c9eb17ecb89cd02e9fac580a32ec794b.zip
Move utility functions from clua.cc to cluautil.cc.
cluautil.cc should eventually contain all of the functions for passing objects from and to lua, at least the shared ones. Also cut down on clua.cc include list.
Diffstat (limited to 'crawl-ref/source/cluautil.cc')
-rw-r--r--crawl-ref/source/cluautil.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/crawl-ref/source/cluautil.cc b/crawl-ref/source/cluautil.cc
new file mode 100644
index 0000000000..291b717a21
--- /dev/null
+++ b/crawl-ref/source/cluautil.cc
@@ -0,0 +1,60 @@
+#include "AppHdr.h"
+
+#include "cluautil.h"
+#include "clua.h"
+#include "l_libs.h"
+
+#include "delay.h"
+
+int push_activity_interrupt(lua_State *ls, activity_interrupt_data *t)
+{
+ if (!t->data)
+ {
+ lua_pushnil(ls);
+ return 0;
+ }
+
+ switch (t->apt)
+ {
+ case AIP_HP_LOSS:
+ {
+ const ait_hp_loss *ahl = (const ait_hp_loss *) t->data;
+ lua_pushnumber(ls, ahl->hp);
+ lua_pushnumber(ls, ahl->hurt_type);
+ return 1;
+ }
+ case AIP_INT:
+ lua_pushnumber(ls, *(const int *) t->data);
+ break;
+ case AIP_STRING:
+ lua_pushstring(ls, (const char *) t->data);
+ break;
+ case AIP_MONSTER:
+ // FIXME: We're casting away the const...
+ push_monster(ls, (monsters *) t->data);
+ break;
+ default:
+ lua_pushnil(ls);
+ break;
+ }
+ return 0;
+}
+
+void clua_push_map(lua_State *ls, map_def *map)
+{
+ map_def **mapref = clua_new_userdata<map_def *>(ls, MAP_METATABLE);
+ *mapref = map;
+}
+
+void clua_push_coord(lua_State *ls, const coord_def &c)
+{
+ lua_pushnumber(ls, c.x);
+ lua_pushnumber(ls, c.y);
+}
+
+void clua_push_dgn_event(lua_State *ls, const dgn_event *devent)
+{
+ const dgn_event **de =
+ clua_new_userdata<const dgn_event *>(ls, DEVENT_METATABLE);
+ *de = devent;
+}