From 32ba97b96685241b1e30299f313c15d20d103998 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sat, 23 Jun 2007 19:58:45 +0000 Subject: Step 1 of .des file Lua-isation. The dungeon compiler converts .des files to Lua (Lua code can be embedded with {{ }} constructs) that is run to produce the final map. Some maps may be broken, this is untested, lots more work needs to be done. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1629 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/clua.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'crawl-ref/source/clua.h') diff --git a/crawl-ref/source/clua.h b/crawl-ref/source/clua.h index 0ec9723544..6759687494 100644 --- a/crawl-ref/source/clua.h +++ b/crawl-ref/source/clua.h @@ -41,7 +41,7 @@ private: class CLua { public: - CLua(bool managed); + CLua(bool managed = true); ~CLua(); lua_State *state(); @@ -63,6 +63,7 @@ public: void setregistry(const char *name); void getregistry(const char *name); + int loadstring(const char *str, const char *context); int execstring(const char *str, const char *context = "init.txt"); int execfile(const char *filename, bool trusted = false); @@ -161,4 +162,48 @@ extern CLua clua; void lua_set_exclusive_item(const item_def *item = NULL); +#define LUAWRAP(name, wrapexpr) \ + static int name(lua_State *ls) \ + { \ + wrapexpr; \ + return (0); \ + } + +#define PLUARET(type, val) \ + lua_push##type(ls, val); \ + return (1); + +#define LUARET1(name, type, val) \ + static int name(lua_State *ls) \ + { \ + lua_push##type(ls, val); \ + return (1); \ + } + +#define LUARET2(name, type, val1, val2) \ + static int name(lua_State *ls) \ + { \ + lua_push##type(ls, val1); \ + lua_push##type(ls, val2); \ + return (2); \ + } + +template +inline static T *util_get_userdata(lua_State *ls, int ndx) +{ + return (lua_islightuserdata(ls, ndx))? + static_cast( lua_touserdata(ls, ndx) ) + : NULL; +} + +template +inline static T *clua_get_userdata(lua_State *ls, const char *mt) +{ + return static_cast( luaL_checkudata( ls, 1, mt ) ); +} + +std::string quote_lua_string(const std::string &s); + +#define MAP_METATABLE "dgn.mtmap" + #endif -- cgit v1.2.3-54-g00ecf