summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-20 00:05:15 +0200
committerRobert Vollmert <rvollmert@gmx.net>2009-10-20 00:44:30 +0200
commita4f9da4c2defdeedba6e172d8c8538f4b1aefe78 (patch)
tree4b381ac5f0ed89bde61acb72472d5a518cc968b7 /crawl-ref
parentfac213f26779fde815580d9c06ea3db367f50942 (diff)
downloadcrawl-ref-a4f9da4c2defdeedba6e172d8c8538f4b1aefe78.tar.gz
crawl-ref-a4f9da4c2defdeedba6e172d8c8538f4b1aefe78.zip
Move part of dgn_lib out to l_dgnevt.cc.
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/dlua.cc1
-rw-r--r--crawl-ref/source/l_dgn.cc51
-rw-r--r--crawl-ref/source/l_dgnevt.cc67
-rw-r--r--crawl-ref/source/l_libs.h2
4 files changed, 68 insertions, 53 deletions
diff --git a/crawl-ref/source/dlua.cc b/crawl-ref/source/dlua.cc
index 3fbb628d77..0775c2635d 100644
--- a/crawl-ref/source/dlua.cc
+++ b/crawl-ref/source/dlua.cc
@@ -307,6 +307,7 @@ void init_dungeon_lua()
lua_stack_cleaner clean(dlua);
luaL_openlib(dlua, "dgn", dgn_lib, 0);
+ luaL_openlib(dlua, "dgn", dgn_event_lib, 0);
// Add additional function to the Crawl module.
luaL_openlib(dlua, "crawl", crawl_lib, 0);
luaL_openlib(dlua, "file", file_lib, 0);
diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc
index 05d29efe9b..1ec9f78050 100644
--- a/crawl-ref/source/l_dgn.cc
+++ b/crawl-ref/source/l_dgn.cc
@@ -1200,56 +1200,6 @@ static int dgn_feature_name(lua_State *ls)
dungeon_feature_name(static_cast<dungeon_feature_type>(feat)));
}
-static const char *dgn_event_type_names[] =
-{
-"none", "turn", "mons_move", "player_move", "leave_level",
-"entering_level", "entered_level", "player_los", "player_climb",
-"monster_dies", "item_pickup", "item_moved", "feat_change",
-"wall_hit"
-};
-
-static dgn_event_type dgn_event_type_by_name(const std::string &name)
-{
- for (unsigned i = 0; i < ARRAYSZ(dgn_event_type_names); ++i)
- if (dgn_event_type_names[i] == name)
- return static_cast<dgn_event_type>(i? 1 << (i - 1) : 0);
- return (DET_NONE);
-}
-
-static const char *dgn_event_type_name(unsigned evmask)
-{
- if (evmask == 0)
- return (dgn_event_type_names[0]);
-
- for (unsigned i = 1; i < ARRAYSZ(dgn_event_type_names); ++i)
- if (evmask & (1 << (i - 1)))
- return (dgn_event_type_names[i]);
-
- return (dgn_event_type_names[0]);
-}
-
-static void dgn_push_event_type(lua_State *ls, int n)
-{
- if (lua_isstring(ls, n))
- lua_pushnumber(ls, dgn_event_type_by_name(lua_tostring(ls, n)));
- else if (lua_isnumber(ls, n))
- lua_pushstring(ls, dgn_event_type_name(luaL_checkint(ls, n)));
- else
- lua_pushnil(ls);
-}
-
-static int dgn_dgn_event(lua_State *ls)
-{
- const int start = lua_isuserdata(ls, 1)? 2 : 1;
- int retvals = 0;
- for (int i = start, nargs = lua_gettop(ls); i <= nargs; ++i)
- {
- dgn_push_event_type(ls, i);
- retvals++;
- }
- return (retvals);
-}
-
static int dgn_register_listener(lua_State *ls)
{
unsigned mask = luaL_checkint(ls, 1);
@@ -2793,7 +2743,6 @@ const struct luaL_reg dgn_lib[] =
{ "load_des_file", dgn_load_des_file },
{ "feature_number", dgn_feature_number },
{ "feature_name", dgn_feature_name },
-{ "dgn_event_type", dgn_dgn_event },
{ "register_listener", dgn_register_listener },
{ "remove_listener", dgn_remove_listener },
{ "remove_marker", dgn_remove_marker },
diff --git a/crawl-ref/source/l_dgnevt.cc b/crawl-ref/source/l_dgnevt.cc
index 875c90b467..73574309fe 100644
--- a/crawl-ref/source/l_dgnevt.cc
+++ b/crawl-ref/source/l_dgnevt.cc
@@ -5,6 +5,10 @@
#include "dgnevent.h"
+/*
+ * Methods for DEVENT_METATABLE.
+ */
+
static int dgnevent_type(lua_State *ls)
{
DEVENT(ls, 1, dev);
@@ -45,7 +49,7 @@ static int dgnevent_arg2(lua_State *ls)
PLUARET(number, dev->arg2);
}
-const struct luaL_reg dgnevent_lib[] =
+static const struct luaL_reg dgnevent_lib[] =
{
{ "type", dgnevent_type },
{ "pos", dgnevent_place },
@@ -60,3 +64,64 @@ void luaopen_dgnevent(lua_State *ls)
{
luaopen_setmeta(ls, "dgnevent", dgnevent_lib, DEVENT_METATABLE);
}
+
+/*
+ * Functions for library "dgn".
+ */
+
+static const char *dgn_event_type_names[] =
+{
+"none", "turn", "mons_move", "player_move", "leave_level",
+"entering_level", "entered_level", "player_los", "player_climb",
+"monster_dies", "item_pickup", "item_moved", "feat_change",
+"wall_hit"
+};
+
+static dgn_event_type dgn_event_type_by_name(const std::string &name)
+{
+ for (unsigned i = 0; i < ARRAYSZ(dgn_event_type_names); ++i)
+ if (dgn_event_type_names[i] == name)
+ return static_cast<dgn_event_type>(i? 1 << (i - 1) : 0);
+ return (DET_NONE);
+}
+
+static const char *dgn_event_type_name(unsigned evmask)
+{
+ if (evmask == 0)
+ return (dgn_event_type_names[0]);
+
+ for (unsigned i = 1; i < ARRAYSZ(dgn_event_type_names); ++i)
+ if (evmask & (1 << (i - 1)))
+ return (dgn_event_type_names[i]);
+
+ return (dgn_event_type_names[0]);
+}
+
+static void dgn_push_event_type(lua_State *ls, int n)
+{
+ if (lua_isstring(ls, n))
+ lua_pushnumber(ls, dgn_event_type_by_name(lua_tostring(ls, n)));
+ else if (lua_isnumber(ls, n))
+ lua_pushstring(ls, dgn_event_type_name(luaL_checkint(ls, n)));
+ else
+ lua_pushnil(ls);
+}
+
+static int dgn_dgn_event(lua_State *ls)
+{
+ const int start = lua_isuserdata(ls, 1)? 2 : 1;
+ int retvals = 0;
+ for (int i = start, nargs = lua_gettop(ls); i <= nargs; ++i)
+ {
+ dgn_push_event_type(ls, i);
+ retvals++;
+ }
+ return (retvals);
+}
+
+const struct luaL_reg dgn_event_lib[] =
+{
+{ "dgn_event_type", dgn_dgn_event },
+
+{ NULL, NULL }
+};
diff --git a/crawl-ref/source/l_libs.h b/crawl-ref/source/l_libs.h
index 2db0b02816..bf721ab3a2 100644
--- a/crawl-ref/source/l_libs.h
+++ b/crawl-ref/source/l_libs.h
@@ -7,7 +7,7 @@
extern const struct luaL_reg crawl_lib[];
extern const struct luaL_reg dgn_lib[];
-extern const struct luaL_reg dgnevent_lib[];
+extern const struct luaL_reg dgn_event_lib[];
extern const struct luaL_reg file_lib[];
extern const struct luaL_reg los_lib[];
extern const struct luaL_reg mapmarker_lib[];