mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Script: Enforce type checks if not nil (#9748)
* Script: Enforce type checks if not nil
This commit is contained in:
parent
515d38a702
commit
be71e70a91
4 changed files with 72 additions and 56 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue