summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-19 23:07:07 +0200
committerRobert Vollmert <rvollmert@gmx.net>2009-10-19 23:11:43 +0200
commit99551ab330ffd7037891fffc159708298159a432 (patch)
treebd398f2c5fb3223f3c3651a9508adbd230ef82fb /crawl-ref
parent5bb58a2e08721ad69df30f5b10af6fef46a4b0d3 (diff)
downloadcrawl-ref-99551ab330ffd7037891fffc159708298159a432.tar.gz
crawl-ref-99551ab330ffd7037891fffc159708298159a432.zip
Split file_lib out.
Move lua library headers to separate l_libs.h, fixing another compilation error...
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/dlua.cc136
-rw-r--r--crawl-ref/source/dlua.h8
-rw-r--r--crawl-ref/source/l_crawl.cc3
-rw-r--r--crawl-ref/source/l_dgn.cc1
-rw-r--r--crawl-ref/source/l_file.cc139
-rw-r--r--crawl-ref/source/l_libs.h12
-rw-r--r--crawl-ref/source/l_los.cc4
-rw-r--r--crawl-ref/source/makefile.obj1
8 files changed, 162 insertions, 142 deletions
diff --git a/crawl-ref/source/dlua.cc b/crawl-ref/source/dlua.cc
index 769a5b1752..d9ce189b36 100644
--- a/crawl-ref/source/dlua.cc
+++ b/crawl-ref/source/dlua.cc
@@ -11,13 +11,15 @@
#include <memory>
#include <cmath>
+#include "dlua.h"
+#include "l_libs.h"
+
#include "branch.h"
#include "chardump.h"
#include "clua.h"
#include "cloud.h"
#include "describe.h"
#include "directn.h"
-#include "dlua.h"
#include "dungeon.h"
#include "files.h"
#include "hiscores.h"
@@ -319,138 +321,6 @@ std::string dlua_chunk::get_chunk_prefix(const std::string &sorig) const
return rewrite_chunk_prefix(sorig, true);
}
-static int file_marshall(lua_State *ls)
-{
- if (lua_gettop(ls) != 2)
- luaL_error(ls, "Need two arguments: tag header and value");
- writer &th(*static_cast<writer*>( lua_touserdata(ls, 1) ));
- if (lua_isnumber(ls, 2))
- marshallLong(th, luaL_checklong(ls, 2));
- else if (lua_isboolean(ls, 2))
- marshallByte(th, lua_toboolean(ls, 2));
- else if (lua_isstring(ls, 2))
- marshallString(th, lua_tostring(ls, 2));
- else if (lua_isfunction(ls, 2))
- {
- dlua_chunk chunk(ls);
- marshallString(th, chunk.compiled_chunk());
- }
- return (0);
-}
-
-static int file_unmarshall_boolean(lua_State *ls)
-{
- if (lua_gettop(ls) != 1)
- luaL_error(ls, "Need reader as one argument");
- reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
- lua_pushboolean(ls, unmarshallByte(th));
- return (1);
-}
-
-static int file_unmarshall_number(lua_State *ls)
-{
- if (lua_gettop(ls) != 1)
- luaL_error(ls, "Need reader as one argument");
- reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
- lua_pushnumber(ls, unmarshallLong(th));
- return (1);
-}
-
-static int file_unmarshall_string(lua_State *ls)
-{
- if (lua_gettop(ls) != 1)
- luaL_error(ls, "Need reader as one argument");
- reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
- lua_pushstring(ls, unmarshallString(th).c_str());
- return (1);
-}
-
-static int file_unmarshall_fn(lua_State *ls)
-{
- if (lua_gettop(ls) != 1)
- luaL_error(ls, "Need reader as one argument");
- reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
- const std::string s(unmarshallString(th, LUA_CHUNK_MAX_SIZE));
- dlua_chunk chunk = dlua_chunk::precompiled(s);
- if (chunk.load(dlua))
- lua_pushnil(ls);
- return (1);
-}
-
-enum lua_persist_type
-{
- LPT_NONE,
- LPT_NUMBER,
- LPT_STRING,
- LPT_FUNCTION,
- LPT_NIL,
- LPT_BOOLEAN
-};
-
-static int file_marshall_meta(lua_State *ls)
-{
- if (lua_gettop(ls) != 2)
- luaL_error(ls, "Need two arguments: tag header and value");
-
- writer &th(*static_cast<writer*>( lua_touserdata(ls, 1) ));
-
- lua_persist_type ptype = LPT_NONE;
- if (lua_isnumber(ls, 2))
- ptype = LPT_NUMBER;
- else if (lua_isboolean(ls, 2))
- ptype = LPT_BOOLEAN;
- else if (lua_isstring(ls, 2))
- ptype = LPT_STRING;
- else if (lua_isfunction(ls, 2))
- ptype = LPT_FUNCTION;
- else if (lua_isnil(ls, 2))
- ptype = LPT_NIL;
- else
- luaL_error(ls,
- make_stringf("Cannot marshall %s",
- lua_typename(ls, lua_type(ls, 2))).c_str());
- marshallByte(th, ptype);
- if (ptype != LPT_NIL)
- file_marshall(ls);
- return (0);
-}
-
-static int file_unmarshall_meta(lua_State *ls)
-{
- reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
- const lua_persist_type ptype =
- static_cast<lua_persist_type>(unmarshallByte(th));
- switch (ptype)
- {
- case LPT_BOOLEAN:
- return file_unmarshall_boolean(ls);
- case LPT_NUMBER:
- return file_unmarshall_number(ls);
- case LPT_STRING:
- return file_unmarshall_string(ls);
- case LPT_FUNCTION:
- return file_unmarshall_fn(ls);
- case LPT_NIL:
- lua_pushnil(ls);
- return (1);
- default:
- luaL_error(ls, "Unexpected type signature.");
- }
- // Never get here.
- return (0);
-}
-
-static const struct luaL_reg file_lib[] =
-{
- { "marshall", file_marshall },
- { "marshall_meta", file_marshall_meta },
- { "unmarshall_meta", file_unmarshall_meta },
- { "unmarshall_number", file_unmarshall_number },
- { "unmarshall_string", file_unmarshall_string },
- { "unmarshall_fn", file_unmarshall_fn },
- { NULL, NULL }
-};
-
LUARET1(you_can_hear_pos, boolean,
player_can_hear(coord_def(luaL_checkint(ls,1), luaL_checkint(ls, 2))))
LUARET1(you_x_pos, number, you.pos().x)
diff --git a/crawl-ref/source/dlua.h b/crawl-ref/source/dlua.h
index 4d3aa4c842..e23fa220b7 100644
--- a/crawl-ref/source/dlua.h
+++ b/crawl-ref/source/dlua.h
@@ -119,14 +119,6 @@ dgn_event *var = *(dgn_event **) luaL_checkudata(ls, n, DEVENT_METATABLE)
#define MAPMARKER(ls, n, var) \
map_marker *var = *(map_marker **) luaL_checkudata(ls, n, MAPMARK_METATABLE)
-extern const struct luaL_reg crawl_lib[];
-extern const struct luaL_reg dgn_lib[];
-extern const struct luaL_reg los_lib[];
-
-void luaopen_ray(lua_State *ls);
-
-void register_mapdef_tables(lua_State *ls);
-
//////////////////////////////////////////////////////////////////////////
#endif
diff --git a/crawl-ref/source/l_crawl.cc b/crawl-ref/source/l_crawl.cc
index 769ce0c768..4306c01801 100644
--- a/crawl-ref/source/l_crawl.cc
+++ b/crawl-ref/source/l_crawl.cc
@@ -1,5 +1,8 @@
#include "AppHdr.h"
+
#include "dlua.h"
+#include "l_libs.h"
+
#include "initfile.h"
#include "view.h"
diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc
index a6e05cf589..05d29efe9b 100644
--- a/crawl-ref/source/l_dgn.cc
+++ b/crawl-ref/source/l_dgn.cc
@@ -1,6 +1,7 @@
#include "AppHdr.h"
#include "dlua.h"
+#include "l_libs.h"
#include <cmath>
diff --git a/crawl-ref/source/l_file.cc b/crawl-ref/source/l_file.cc
new file mode 100644
index 0000000000..5e204dbceb
--- /dev/null
+++ b/crawl-ref/source/l_file.cc
@@ -0,0 +1,139 @@
+#include "AppHdr.h"
+
+#include "dlua.h"
+#include "l_libs.h"
+
+#include "tags.h"
+
+static int file_marshall(lua_State *ls)
+{
+ if (lua_gettop(ls) != 2)
+ luaL_error(ls, "Need two arguments: tag header and value");
+ writer &th(*static_cast<writer*>( lua_touserdata(ls, 1) ));
+ if (lua_isnumber(ls, 2))
+ marshallLong(th, luaL_checklong(ls, 2));
+ else if (lua_isboolean(ls, 2))
+ marshallByte(th, lua_toboolean(ls, 2));
+ else if (lua_isstring(ls, 2))
+ marshallString(th, lua_tostring(ls, 2));
+ else if (lua_isfunction(ls, 2))
+ {
+ dlua_chunk chunk(ls);
+ marshallString(th, chunk.compiled_chunk());
+ }
+ return (0);
+}
+
+static int file_unmarshall_boolean(lua_State *ls)
+{
+ if (lua_gettop(ls) != 1)
+ luaL_error(ls, "Need reader as one argument");
+ reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
+ lua_pushboolean(ls, unmarshallByte(th));
+ return (1);
+}
+
+static int file_unmarshall_number(lua_State *ls)
+{
+ if (lua_gettop(ls) != 1)
+ luaL_error(ls, "Need reader as one argument");
+ reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
+ lua_pushnumber(ls, unmarshallLong(th));
+ return (1);
+}
+
+static int file_unmarshall_string(lua_State *ls)
+{
+ if (lua_gettop(ls) != 1)
+ luaL_error(ls, "Need reader as one argument");
+ reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
+ lua_pushstring(ls, unmarshallString(th).c_str());
+ return (1);
+}
+
+static int file_unmarshall_fn(lua_State *ls)
+{
+ if (lua_gettop(ls) != 1)
+ luaL_error(ls, "Need reader as one argument");
+ reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
+ const std::string s(unmarshallString(th, LUA_CHUNK_MAX_SIZE));
+ dlua_chunk chunk = dlua_chunk::precompiled(s);
+ if (chunk.load(dlua))
+ lua_pushnil(ls);
+ return (1);
+}
+
+enum lua_persist_type
+{
+ LPT_NONE,
+ LPT_NUMBER,
+ LPT_STRING,
+ LPT_FUNCTION,
+ LPT_NIL,
+ LPT_BOOLEAN
+};
+
+static int file_marshall_meta(lua_State *ls)
+{
+ if (lua_gettop(ls) != 2)
+ luaL_error(ls, "Need two arguments: tag header and value");
+
+ writer &th(*static_cast<writer*>( lua_touserdata(ls, 1) ));
+
+ lua_persist_type ptype = LPT_NONE;
+ if (lua_isnumber(ls, 2))
+ ptype = LPT_NUMBER;
+ else if (lua_isboolean(ls, 2))
+ ptype = LPT_BOOLEAN;
+ else if (lua_isstring(ls, 2))
+ ptype = LPT_STRING;
+ else if (lua_isfunction(ls, 2))
+ ptype = LPT_FUNCTION;
+ else if (lua_isnil(ls, 2))
+ ptype = LPT_NIL;
+ else
+ luaL_error(ls,
+ make_stringf("Cannot marshall %s",
+ lua_typename(ls, lua_type(ls, 2))).c_str());
+ marshallByte(th, ptype);
+ if (ptype != LPT_NIL)
+ file_marshall(ls);
+ return (0);
+}
+
+static int file_unmarshall_meta(lua_State *ls)
+{
+ reader &th(*static_cast<reader*>( lua_touserdata(ls, 1) ));
+ const lua_persist_type ptype =
+ static_cast<lua_persist_type>(unmarshallByte(th));
+ switch (ptype)
+ {
+ case LPT_BOOLEAN:
+ return file_unmarshall_boolean(ls);
+ case LPT_NUMBER:
+ return file_unmarshall_number(ls);
+ case LPT_STRING:
+ return file_unmarshall_string(ls);
+ case LPT_FUNCTION:
+ return file_unmarshall_fn(ls);
+ case LPT_NIL:
+ lua_pushnil(ls);
+ return (1);
+ default:
+ luaL_error(ls, "Unexpected type signature.");
+ }
+ // Never get here.
+ return (0);
+}
+
+const struct luaL_reg file_lib[] =
+{
+{ "marshall", file_marshall },
+{ "marshall_meta", file_marshall_meta },
+{ "unmarshall_meta", file_unmarshall_meta },
+{ "unmarshall_number", file_unmarshall_number },
+{ "unmarshall_string", file_unmarshall_string },
+{ "unmarshall_fn", file_unmarshall_fn },
+{ NULL, NULL }
+};
+
diff --git a/crawl-ref/source/l_libs.h b/crawl-ref/source/l_libs.h
new file mode 100644
index 0000000000..a0e926d177
--- /dev/null
+++ b/crawl-ref/source/l_libs.h
@@ -0,0 +1,12 @@
+#include "clua.h"
+
+extern const struct luaL_reg crawl_lib[];
+extern const struct luaL_reg dgn_lib[];
+extern const struct luaL_reg file_lib[];
+extern const struct luaL_reg los_lib[];
+
+void luaopen_ray(lua_State *ls);
+
+void register_mapdef_tables(lua_State *ls);
+
+
diff --git a/crawl-ref/source/l_los.cc b/crawl-ref/source/l_los.cc
index 8ccd2ffa07..b4d0f86fa1 100644
--- a/crawl-ref/source/l_los.cc
+++ b/crawl-ref/source/l_los.cc
@@ -6,8 +6,10 @@
#include "AppHdr.h"
-#include "los.h"
#include "dlua.h"
+#include "l_libs.h"
+
+#include "los.h"
#include "ray.h"
#define RAY_METATABLE "dgn.ray"
diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj
index 19c7d81b7f..892a6db740 100644
--- a/crawl-ref/source/makefile.obj
+++ b/crawl-ref/source/makefile.obj
@@ -40,6 +40,7 @@ lev-pand.o \
libutil.o \
l_crawl.o \
l_dgn.o \
+l_file.o \
l_los.o \
los.o \
losparam.o \