mirror of
https://github.com/moparisthebest/minetest
synced 2024-12-22 23:58:48 -05:00
Allow non-string arguments for minetest.is_yes()
This commit is contained in:
parent
d820a6bfd8
commit
dd5c451e03
@ -1069,8 +1069,8 @@ minetest.pos_to_string({x=X,y=Y,z=Z}) -> "(X,Y,Z)"
|
|||||||
minetest.string_to_pos(string) -> position
|
minetest.string_to_pos(string) -> position
|
||||||
^ Same but in reverse
|
^ Same but in reverse
|
||||||
^ escapes characters [ ] \ , ; that can not be used in formspecs
|
^ escapes characters [ ] \ , ; that can not be used in formspecs
|
||||||
minetest.is_yes(string)
|
minetest.is_yes(arg)
|
||||||
^ returns whether string can be interpreted as yes
|
^ returns whether arg can be interpreted as yes
|
||||||
|
|
||||||
minetest namespace reference
|
minetest namespace reference
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
@ -182,8 +182,8 @@ string:split(separator)
|
|||||||
^ eg. string:split("a,b", ",") == {"a","b"}
|
^ eg. string:split("a,b", ",") == {"a","b"}
|
||||||
string:trim()
|
string:trim()
|
||||||
^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
|
^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
|
||||||
minetest.is_yes(string)
|
minetest.is_yes(arg)
|
||||||
^ returns whether string can be interpreted as yes
|
^ returns whether arg can be interpreted as yes
|
||||||
|
|
||||||
Class reference
|
Class reference
|
||||||
----------------
|
----------------
|
||||||
|
@ -220,11 +220,17 @@ int ModApiUtil::l_get_password_hash(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_yes(string)
|
// is_yes(arg)
|
||||||
int ModApiUtil::l_is_yes(lua_State *L)
|
int ModApiUtil::l_is_yes(lua_State *L)
|
||||||
{
|
{
|
||||||
NO_MAP_LOCK_REQUIRED;
|
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);
|
bool yes = is_yes(str);
|
||||||
lua_pushboolean(L, yes);
|
lua_pushboolean(L, yes);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -71,7 +71,7 @@ private:
|
|||||||
// get_password_hash(name, raw_password)
|
// get_password_hash(name, raw_password)
|
||||||
static int l_get_password_hash(lua_State *L);
|
static int l_get_password_hash(lua_State *L);
|
||||||
|
|
||||||
// is_yes(string)
|
// is_yes(arg)
|
||||||
static int l_is_yes(lua_State *L);
|
static int l_is_yes(lua_State *L);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user