diff options
author | PilzAdam <pilzadam@minetest.net> | 2013-09-10 19:24:17 +0200 |
---|---|---|
committer | PilzAdam <pilzadam@minetest.net> | 2013-09-10 21:38:44 +0200 |
commit | dd5c451e0349f57657010e3f89f3310412984ba9 (patch) | |
tree | e7650524d72ae96d820e1e137871cea485b65259 /src | |
parent | d820a6bfd807b6d181a858f3ea8a0d0f5c2b1879 (diff) | |
download | minetest-dd5c451e0349f57657010e3f89f3310412984ba9.tar.gz minetest-dd5c451e0349f57657010e3f89f3310412984ba9.tar.bz2 minetest-dd5c451e0349f57657010e3f89f3310412984ba9.zip |
Allow non-string arguments for minetest.is_yes()
Diffstat (limited to 'src')
-rw-r--r-- | src/script/lua_api/l_util.cpp | 10 | ||||
-rw-r--r-- | src/script/lua_api/l_util.h | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 34788accd..af9c19210 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -220,11 +220,17 @@ int ModApiUtil::l_get_password_hash(lua_State *L) return 1; } -// is_yes(string) +// is_yes(arg) int ModApiUtil::l_is_yes(lua_State *L) { NO_MAP_LOCK_REQUIRED; - std::string str = luaL_checkstring(L, 1); + + lua_getglobal(L, "tostring"); // function to be called + lua_pushvalue(L, 1); // 1st argument + lua_call(L, 1, 1); // execute function + std::string str(lua_tostring(L, -1)); // get result + lua_pop(L, 1); + bool yes = is_yes(str); lua_pushboolean(L, yes); return 1; diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h index ae2163ec8..bb99e1562 100644 --- a/src/script/lua_api/l_util.h +++ b/src/script/lua_api/l_util.h @@ -71,7 +71,7 @@ private: // get_password_hash(name, raw_password) static int l_get_password_hash(lua_State *L); - // is_yes(string) + // is_yes(arg) static int l_is_yes(lua_State *L); public: |