summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-20 16:54:58 +0200
committerRobert Vollmert <rvollmert@gmx.net>2009-10-20 16:57:51 +0200
commita99ad56b2d84c930ee7c0ff4628c96eed1d200dc (patch)
tree9c1dd0b895c0236c6b7ffff078569dab781a8d9a /crawl-ref/source
parentdd65128ada0a1e92cebe85f5353113a8427ab043 (diff)
downloadcrawl-ref-a99ad56b2d84c930ee7c0ff4628c96eed1d200dc.tar.gz
crawl-ref-a99ad56b2d84c930ee7c0ff4628c96eed1d200dc.zip
Move grd_lib out of clua.cc into l_mapgrd.cc.
Rest of commit comment only as accurate as my understanding... Renaming from grd to mapgrd to avoid confusion with grd == env.grid: This grd is the maplines-section of a vault definition. Also move mapgrd_lib from clua to dlua since it's only used for dungeon building. clua and dlua need more descriptive names.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/clua.cc105
-rw-r--r--crawl-ref/source/clua.h4
-rw-r--r--crawl-ref/source/dlua.cc1
-rw-r--r--crawl-ref/source/l_dgnbld.cc2
-rw-r--r--crawl-ref/source/l_libs.h5
-rw-r--r--crawl-ref/source/l_mapgrd.cc109
-rw-r--r--crawl-ref/source/makefile.obj1
7 files changed, 117 insertions, 110 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 384b9cce1b..da9cc20ecf 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -596,7 +596,6 @@ void luaopen_food(lua_State *ls);
void luaopen_file(lua_State *ls);
void luaopen_options(lua_State *ls);
void luaopen_monsters(lua_State *ls);
-void luaopen_grd(lua_State *ls);
void luaopen_globals(lua_State *ls);
void CLua::init_lua()
@@ -626,7 +625,6 @@ void CLua::init_lua()
luaopen_file(_state);
luaopen_options(_state);
luaopen_monsters(_state);
- luaopen_grd(_state);
luaopen_globals(_state);
@@ -1998,109 +1996,6 @@ void luaopen_monsters(lua_State *ls)
luaL_openlib(ls, "mons", mons_lib, 0);
}
-/////////////////////////////////////////////////////////////////////
-// grd and grd_col handling (i.e. map_lines in a metatable)
-
-struct mapcolumn
-{
- map_def* map;
- int col;
-};
-
-static int grd_get(lua_State *ls)
-{
- // Return a metatable for this column in the map grid.
- map_def *map = *(map_def **) luaL_checkudata(ls, 1, GRD_METATABLE);
-
- int column = luaL_checkint(ls, 2);
-
- mapcolumn *mapref = clua_new_userdata<mapcolumn>(ls, GRD_COL_METATABLE);
- mapref->map = map;
- mapref->col = column;
-
- return (1);
-}
-
-static int grd_set(lua_State *ls)
-{
- return (luaL_error(ls, "%s", "Cannot assign to read-only table."));
-}
-
-static char* grd_glyph(lua_State *ls, int &col, int &row)
-{
- mapcolumn *mapc = (mapcolumn *)luaL_checkudata(ls, 1, GRD_COL_METATABLE);
- row = luaL_checkint(ls, 2);
- col = mapc->col;
-
- map_lines &lines = mapc->map->map;
- if (row < 1 || col < 1 || col > lines.width() || row > lines.height())
- {
- return (NULL);
- }
-
- coord_def mc(col - 1, row - 1);
- return (&lines(mc));
-}
-
-static int grd_col_get(lua_State *ls)
-{
- int col, row;
- char *gly = grd_glyph(ls, col, row);
- if (!gly)
- return (luaL_error(ls, "Invalid coords: %d, %d", col, row));
-
- char buf[2];
- buf[0] = *gly;
- buf[1] = '\0';
-
- lua_pushstring(ls, buf);
-
- return (1);
-}
-
-static int grd_col_set(lua_State *ls)
-{
- int col, row;
- char *gly = grd_glyph(ls, col, row);
- if (!gly)
- return (luaL_error(ls, "Invalid coords: %d, %d", col, row));
-
- const char *str = luaL_checkstring(ls, 3);
- if (!str[0] || str[1])
- return (luaL_error(ls, "%s", "grd must be set to a single char."));
-
- (*gly) = str[0];
-
- return (0);
-}
-
-void luaopen_grd(lua_State *ls)
-{
- // grd table
- luaL_newmetatable(ls, GRD_METATABLE);
- lua_pushstring(ls, "__index");
- lua_pushcfunction(ls, grd_get);
- lua_settable(ls, -3);
-
- lua_pushstring(ls, "__newindex");
- lua_pushcfunction(ls, grd_set);
- lua_settable(ls, -3);
-
- lua_pop(ls, 1);
-
- // grd col table
- luaL_newmetatable(ls, GRD_COL_METATABLE);
- lua_pushstring(ls, "__index");
- lua_pushcfunction(ls, grd_col_get);
- lua_settable(ls, -3);
-
- lua_pushstring(ls, "__newindex");
- lua_pushcfunction(ls, grd_col_set);
- lua_settable(ls, -3);
-
- lua_pop(ls, 1);
-}
-
//////////////////////////////////////////////////////////////////////
// Miscellaneous globals
diff --git a/crawl-ref/source/clua.h b/crawl-ref/source/clua.h
index f98e80076f..bc723c0d90 100644
--- a/crawl-ref/source/clua.h
+++ b/crawl-ref/source/clua.h
@@ -320,7 +320,7 @@ void print_clua_stack();
#define MAP_METATABLE "dgn.mtmap"
#define DEVENT_METATABLE "dgn.devent"
#define MAPMARK_METATABLE "dgn.mapmark"
-#define GRD_METATABLE "dgn.grd"
-#define GRD_COL_METATABLE "dgn.grdcol"
+#define MAPGRD_METATABLE "dgn.mapgrd"
+#define MAPGRD_COL_METATABLE "dgn.mapgrdcol"
#endif
diff --git a/crawl-ref/source/dlua.cc b/crawl-ref/source/dlua.cc
index fa94dd8780..dc800406ca 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);
dluaopen_crawl(dlua);
+ dluaopen_mapgrd(dlua);
dluaopen_you(dlua);
luaL_openlib(dlua, "dgn", dgn_dlib, 0);
diff --git a/crawl-ref/source/l_dgnbld.cc b/crawl-ref/source/l_dgnbld.cc
index bb51b62bf4..2f3fd0816e 100644
--- a/crawl-ref/source/l_dgnbld.cc
+++ b/crawl-ref/source/l_dgnbld.cc
@@ -17,7 +17,7 @@ static int dgn_grd_table(lua_State *ls)
{
MAP(ls, 1, map);
- map_def **mapref = clua_new_userdata<map_def *>(ls, GRD_METATABLE);
+ map_def **mapref = clua_new_userdata<map_def *>(ls, MAPGRD_METATABLE);
*mapref = map;
return (1);
diff --git a/crawl-ref/source/l_libs.h b/crawl-ref/source/l_libs.h
index a101e423c4..9fe6d97eb3 100644
--- a/crawl-ref/source/l_libs.h
+++ b/crawl-ref/source/l_libs.h
@@ -15,7 +15,6 @@
void cluaopen_crawl(lua_State *ls);
void cluaopen_you(lua_State *ls);
-
/*
* Libraries and loaders, accessed from init_dungeon_lua().
*/
@@ -42,7 +41,9 @@ void register_itemlist(lua_State *ls);
void register_builder_funcs(lua_State *ls);
void dluaopen_crawl(lua_State *ls);
-void dluaopen_you(lua_State *ls);
+void dluaopen_mapgrd(lua_State *ls);
+void dluaopen_you(lua_State *ls);
+
/*
* Macros for processing object arguments.
*/
diff --git a/crawl-ref/source/l_mapgrd.cc b/crawl-ref/source/l_mapgrd.cc
new file mode 100644
index 0000000000..0c63238c79
--- /dev/null
+++ b/crawl-ref/source/l_mapgrd.cc
@@ -0,0 +1,109 @@
+#include "AppHdr.h"
+
+#include "dlua.h"
+#include "l_libs.h"
+
+#include "mapdef.h"
+
+/////////////////////////////////////////////////////////////////////
+// grd and grd_col handling (i.e. map_lines in a metatable)
+
+struct mapcolumn
+{
+ map_def* map;
+ int col;
+};
+
+static int grd_get(lua_State *ls)
+{
+ // Return a metatable for this column in the map grid.
+ map_def *map = *(map_def **) luaL_checkudata(ls, 1, MAPGRD_METATABLE);
+
+ int column = luaL_checkint(ls, 2);
+
+ mapcolumn *mapref = clua_new_userdata<mapcolumn>(ls, MAPGRD_COL_METATABLE);
+ mapref->map = map;
+ mapref->col = column;
+
+ return (1);
+}
+
+static int grd_set(lua_State *ls)
+{
+ return (luaL_error(ls, "%s", "Cannot assign to read-only table."));
+}
+
+static char* grd_glyph(lua_State *ls, int &col, int &row)
+{
+ mapcolumn *mapc = (mapcolumn *)luaL_checkudata(ls, 1, MAPGRD_COL_METATABLE);
+ row = luaL_checkint(ls, 2);
+ col = mapc->col;
+
+ map_lines &lines = mapc->map->map;
+ if (row < 1 || col < 1 || col > lines.width() || row > lines.height())
+ {
+ return (NULL);
+ }
+
+ coord_def mc(col - 1, row - 1);
+ return (&lines(mc));
+}
+
+static int grd_col_get(lua_State *ls)
+{
+ int col, row;
+ char *gly = grd_glyph(ls, col, row);
+ if (!gly)
+ return (luaL_error(ls, "Invalid coords: %d, %d", col, row));
+
+ char buf[2];
+ buf[0] = *gly;
+ buf[1] = '\0';
+
+ lua_pushstring(ls, buf);
+
+ return (1);
+}
+
+static int grd_col_set(lua_State *ls)
+{
+ int col, row;
+ char *gly = grd_glyph(ls, col, row);
+ if (!gly)
+ return (luaL_error(ls, "Invalid coords: %d, %d", col, row));
+
+ const char *str = luaL_checkstring(ls, 3);
+ if (!str[0] || str[1])
+ return (luaL_error(ls, "%s", "grd must be set to a single char."));
+
+ (*gly) = str[0];
+
+ return (0);
+}
+
+void dluaopen_mapgrd(lua_State *ls)
+{
+ // grd table
+ luaL_newmetatable(ls, MAPGRD_METATABLE);
+ lua_pushstring(ls, "__index");
+ lua_pushcfunction(ls, grd_get);
+ lua_settable(ls, -3);
+
+ lua_pushstring(ls, "__newindex");
+ lua_pushcfunction(ls, grd_set);
+ lua_settable(ls, -3);
+
+ lua_pop(ls, 1);
+
+ // grd col table
+ luaL_newmetatable(ls, MAPGRD_COL_METATABLE);
+ lua_pushstring(ls, "__index");
+ lua_pushcfunction(ls, grd_col_get);
+ lua_settable(ls, -3);
+
+ lua_pushstring(ls, "__newindex");
+ lua_pushcfunction(ls, grd_col_set);
+ lua_settable(ls, -3);
+
+ lua_pop(ls, 1);
+}
diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj
index f7fc638b3a..4bf1217c60 100644
--- a/crawl-ref/source/makefile.obj
+++ b/crawl-ref/source/makefile.obj
@@ -51,6 +51,7 @@ l_dgntil.o \
l_dgn_bf.o \
l_file.o \
l_los.o \
+l_mapgrd.o \
l_mapmrk.o \
l_you.o \
los.o \