summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_crawl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/l_crawl.cc')
-rw-r--r--crawl-ref/source/l_crawl.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/crawl-ref/source/l_crawl.cc b/crawl-ref/source/l_crawl.cc
index d3bf402d9d..01ea5ce8f0 100644
--- a/crawl-ref/source/l_crawl.cc
+++ b/crawl-ref/source/l_crawl.cc
@@ -3,6 +3,8 @@
#include "dlua.h"
#include "l_libs.h"
#include "initfile.h"
+#include "itemname.h"
+#include "stuff.h"
#include "view.h"
#ifdef UNIX
@@ -45,6 +47,30 @@ LUAFN(_crawl_millis)
}
#endif
+std::string _crawl_make_name (lua_State *ls)
+{
+ // A quick wrapper around itemname:make_name. Seed is random_int().
+ // Possible parameters: all caps, max length, char start. By default
+ // these are false, -1, and 0 as per make_name.
+ if (lua_gettop(ls) == 0)
+ return make_name (random_int(), false);
+ else
+ {
+ bool all_caps (false);
+ int maxlen = -1;
+ char start = 0;
+ if (lua_gettop(ls) >= 1 && lua_isboolean(ls, 1)) // Want all caps.
+ all_caps = lua_toboolean(ls, 1);
+ if (lua_gettop(ls) >= 2 && lua_isnumber(ls, 2)) // Specified a maxlen.
+ maxlen = lua_tonumber(ls, 2);
+ if (lua_gettop(ls) >= 3 && lua_isstring(ls, 3)) // Specificied a start character
+ start = lua_tostring(ls, 3)[0];
+ return make_name (random_int(), all_caps, maxlen, start);
+ }
+}
+
+LUARET1(crawl_make_name, string, _crawl_make_name(ls).c_str())
+
const struct luaL_reg crawl_lib[] =
{
{ "args", _crawl_args },
@@ -53,6 +79,7 @@ const struct luaL_reg crawl_lib[] =
#ifdef UNIX
{ "millis", _crawl_millis },
#endif
+{ "make_name", crawl_make_name },
{ NULL, NULL }
};