diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-20 14:54:25 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-20 15:00:06 +0200 |
commit | f26a5d74bd0b476c24237432be3f940826c05bb7 (patch) | |
tree | 84701afca793ea299016aada66312161ec62bb75 /crawl-ref/source/l_crawl.cc | |
parent | a4870dc24854a206a5243850f05fbb4130c7374e (diff) | |
download | crawl-ref-f26a5d74bd0b476c24237432be3f940826c05bb7.tar.gz crawl-ref-f26a5d74bd0b476c24237432be3f940826c05bb7.zip |
Simplify make_name binding and silence int cast warning.
Diffstat (limited to 'crawl-ref/source/l_crawl.cc')
-rw-r--r-- | crawl-ref/source/l_crawl.cc | 27 |
1 files changed, 13 insertions, 14 deletions
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()) |