mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Modernize lua read (part 2 & 3): C++ templating assurance (#7410)
* Modernize lua read (part 2 & 3): C++ templating assurance Implement the boolean reader Implement the string reader Also remove unused & unimplemented script_error_handler Add a reader with default value
This commit is contained in:
parent
227c71eb76
commit
eef62c82a2
35 changed files with 247 additions and 154 deletions
|
@ -57,8 +57,7 @@ bool ScriptApiClient::on_sending_message(const std::string &message)
|
|||
// Call callbacks
|
||||
lua_pushstring(L, message.c_str());
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
bool ate = lua_toboolean(L, -1);
|
||||
return ate;
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_receiving_message(const std::string &message)
|
||||
|
@ -71,8 +70,7 @@ bool ScriptApiClient::on_receiving_message(const std::string &message)
|
|||
// Call callbacks
|
||||
lua_pushstring(L, message.c_str());
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
bool ate = lua_toboolean(L, -1);
|
||||
return ate;
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
void ScriptApiClient::on_damage_taken(int32_t damage_amount)
|
||||
|
@ -186,8 +184,7 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)
|
|||
|
||||
// Call functions
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
bool blocked = lua_toboolean(L, -1);
|
||||
return blocked;
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefinition &item)
|
||||
|
@ -204,7 +201,7 @@ bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefini
|
|||
|
||||
// Call functions
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
return lua_toboolean(L, -1);
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &pointed)
|
||||
|
@ -221,7 +218,7 @@ bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &poi
|
|||
|
||||
// Call functions
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
return lua_toboolean(L, -1);
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_inventory_open(Inventory *inventory)
|
||||
|
@ -242,7 +239,7 @@ bool ScriptApiClient::on_inventory_open(Inventory *inventory)
|
|||
}
|
||||
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR);
|
||||
return lua_toboolean(L, -1);
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
void ScriptApiClient::setEnv(ClientEnvironment *env)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue