diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2020-04-27 07:02:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-27 07:02:39 +0200 |
commit | be71e70a91a3c857652a8b037dac7adf9d0fcdd1 (patch) | |
tree | ec16ade79fa9c458eb184b2d5b92ce106ec2d4b6 /src/script/common/c_converter.h | |
parent | 515d38a702f0ebe1f419ce38c86484ecb845ed36 (diff) | |
download | hax-minetest-server-be71e70a91a3c857652a8b037dac7adf9d0fcdd1.tar.gz hax-minetest-server-be71e70a91a3c857652a8b037dac7adf9d0fcdd1.zip |
Script: Enforce type checks if not nil (#9748)
* Script: Enforce type checks if not nil
Diffstat (limited to 'src/script/common/c_converter.h')
-rw-r--r-- | src/script/common/c_converter.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 9620bf75a..a4a7079fd 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -45,13 +45,15 @@ float getfloatfield_default(lua_State *L, int table, int getintfield_default(lua_State *L, int table, const char *fieldname, int default_); +bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname); + template<typename T> bool getintfield(lua_State *L, int table, const char *fieldname, T &result) { lua_getfield(L, table, fieldname); bool got = false; - if (lua_isnumber(L, -1)){ + if (check_field_or_nil(L, -1, LUA_TNUMBER, fieldname)){ result = lua_tointeger(L, -1); got = true; } @@ -87,8 +89,6 @@ bool getboolfield(lua_State *L, int table, const char *fieldname, bool &result); bool getfloatfield(lua_State *L, int table, const char *fieldname, float &result); -std::string checkstringfield(lua_State *L, int table, - const char *fieldname); void setstringfield(lua_State *L, int table, const char *fieldname, const std::string &value); |