From f26a5d74bd0b476c24237432be3f940826c05bb7 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Tue, 20 Oct 2009 14:54:25 +0200 Subject: Simplify make_name binding and silence int cast warning. --- crawl-ref/source/l_crawl.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'crawl-ref/source/l_crawl.cc') diff --git a/crawl-ref/source/l_crawl.cc b/crawl-ref/source/l_crawl.cc index 01ea5ce8f0..b50a407a49 100644 --- a/crawl-ref/source/l_crawl.cc +++ b/crawl-ref/source/l_crawl.cc @@ -47,26 +47,25 @@ LUAFN(_crawl_millis) } #endif -std::string _crawl_make_name (lua_State *ls) +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)) + all_caps = lua_toboolean(ls, 1); + if (lua_gettop(ls) >= 2 && lua_isnumber(ls, 2)) + maxlen = luaL_checkint(ls, 2); + if (lua_gettop(ls) >= 3 && lua_isstring(ls, 3)) { - 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); + const char* s = luaL_checkstring(ls, 3); + if (s && *s) + start = *s; } + return make_name(random_int(), all_caps, maxlen, start); } LUARET1(crawl_make_name, string, _crawl_make_name(ls).c_str()) -- cgit v1.2.3-54-g00ecf