mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-15 01:25:20 +02:00
Script: Enforce type checks if not nil (#9748)
* Script: Enforce type checks if not nil
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user