Optimize parameter passing to avoid unnecessary copying
This commit is contained in:
@@ -103,7 +103,7 @@ static int l_reconfig_packs(lua_State* L) {
|
||||
static int l_get_setting(lua_State* L) {
|
||||
auto name = lua_tostring(L, 1);
|
||||
const auto value = scripting::engine->getSettingsHandler().getValue(name);
|
||||
scripting::state->pushvalue(std::move(value));
|
||||
scripting::state->pushvalue(value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -494,7 +494,7 @@ static void p_set_inventory(UINode* node, int idx) {
|
||||
}
|
||||
}
|
||||
}
|
||||
static void p_set_focused(std::shared_ptr<UINode> node, int idx) {
|
||||
static void p_set_focused(const std::shared_ptr<UINode> &node, int idx) {
|
||||
if (state->toboolean(idx) && !node->isFocused()) {
|
||||
scripting::engine->getGUI()->setFocus(node);
|
||||
} else if (node->isFocused()){
|
||||
|
||||
@@ -37,7 +37,7 @@ const ContentIndices* scripting::indices = nullptr;
|
||||
BlocksController* scripting::blocks = nullptr;
|
||||
LevelController* scripting::controller = nullptr;
|
||||
|
||||
void load_script(fs::path name) {
|
||||
void load_script(const fs::path& name) {
|
||||
auto paths = scripting::engine->getPaths();
|
||||
fs::path file = paths->getResources()/fs::path("scripts")/name;
|
||||
|
||||
@@ -72,7 +72,7 @@ scriptenv scripting::create_pack_environment(const ContentPack& pack) {
|
||||
});
|
||||
}
|
||||
|
||||
scriptenv scripting::create_doc_environment(scriptenv parent, const std::string& name) {
|
||||
scriptenv scripting::create_doc_environment(const scriptenv& parent, const std::string& name) {
|
||||
int id = state->createEnvironment(*parent);
|
||||
state->pushenv(id);
|
||||
state->pushvalue(-1);
|
||||
@@ -279,7 +279,7 @@ bool scripting::register_event(int env, const std::string& name, const std::stri
|
||||
return false;
|
||||
}
|
||||
|
||||
void scripting::load_block_script(scriptenv senv, std::string prefix, fs::path file, block_funcs_set& funcsset) {
|
||||
void scripting::load_block_script(const scriptenv& senv, const std::string& prefix, const fs::path& file, block_funcs_set& funcsset) {
|
||||
int env = *senv;
|
||||
std::string src = files::read_string(file);
|
||||
logger.info() << "script (block) " << file.u8string();
|
||||
@@ -293,7 +293,7 @@ void scripting::load_block_script(scriptenv senv, std::string prefix, fs::path f
|
||||
funcsset.onblockstick = register_event(env, "on_blocks_tick", prefix+".blockstick");
|
||||
}
|
||||
|
||||
void scripting::load_item_script(scriptenv senv, std::string prefix, fs::path file, item_funcs_set& funcsset) {
|
||||
void scripting::load_item_script(const scriptenv& senv, const std::string& prefix, const fs::path& file, item_funcs_set& funcsset) {
|
||||
int env = *senv;
|
||||
std::string src = files::read_string(file);
|
||||
logger.info() << "script (item) " << file.u8string();
|
||||
@@ -305,7 +305,7 @@ void scripting::load_item_script(scriptenv senv, std::string prefix, fs::path fi
|
||||
funcsset.on_block_break_by = register_event(env, "on_block_break_by", prefix+".blockbreakby");
|
||||
}
|
||||
|
||||
void scripting::load_world_script(scriptenv senv, std::string prefix, fs::path file) {
|
||||
void scripting::load_world_script(const scriptenv& senv, const std::string& prefix, const fs::path& file) {
|
||||
int env = *senv;
|
||||
|
||||
std::string src = files::read_string(file);
|
||||
@@ -321,7 +321,7 @@ void scripting::load_world_script(scriptenv senv, std::string prefix, fs::path f
|
||||
register_event(env, "on_world_quit", prefix+".worldquit");
|
||||
}
|
||||
|
||||
void scripting::load_layout_script(scriptenv senv, std::string prefix, fs::path file, uidocscript& script) {
|
||||
void scripting::load_layout_script(const scriptenv& senv, const std::string& prefix, const fs::path& file, uidocscript& script) {
|
||||
int env = *senv;
|
||||
|
||||
std::string src = files::read_string(file);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace scripting {
|
||||
|
||||
scriptenv get_root_environment();
|
||||
scriptenv create_pack_environment(const ContentPack& pack);
|
||||
scriptenv create_doc_environment(scriptenv parent, const std::string& name);
|
||||
scriptenv create_doc_environment(const scriptenv& parent, const std::string& name);
|
||||
|
||||
void process_post_runnables();
|
||||
|
||||
@@ -88,27 +88,27 @@ namespace scripting {
|
||||
/// @param prefix pack id
|
||||
/// @param file item script file
|
||||
/// @param funcsset block callbacks set
|
||||
void load_block_script(scriptenv env, std::string prefix, fs::path file, block_funcs_set& funcsset);
|
||||
void load_block_script(const scriptenv& env, const std::string& prefix, const fs::path& file, block_funcs_set& funcsset);
|
||||
|
||||
/// @brief Load script associated with an Item
|
||||
/// @param env environment
|
||||
/// @param prefix pack id
|
||||
/// @param file item script file
|
||||
/// @param funcsset item callbacks set
|
||||
void load_item_script(scriptenv env, std::string prefix, fs::path file, item_funcs_set& funcsset);
|
||||
void load_item_script(const scriptenv& env, const std::string& prefix, const fs::path& file, item_funcs_set& funcsset);
|
||||
|
||||
/// @brief Load package-specific world script
|
||||
/// @param env environment
|
||||
/// @param packid content-pack id
|
||||
/// @param file script file path
|
||||
void load_world_script(scriptenv env, std::string packid, fs::path file);
|
||||
void load_world_script(const scriptenv& env, const std::string& packid, const fs::path& file);
|
||||
|
||||
/// @brief Load script associated with an UiDocument
|
||||
/// @param env environment
|
||||
/// @param prefix pack id
|
||||
/// @param file item script file
|
||||
/// @param script document script info
|
||||
void load_layout_script(scriptenv env, std::string prefix, fs::path file, uidocscript& script);
|
||||
void load_layout_script(const scriptenv& env, const std::string& prefix, const fs::path& file, uidocscript& script);
|
||||
|
||||
/// @brief Finalize lua state. Using scripting after will lead to Lua panic
|
||||
void close();
|
||||
|
||||
@@ -40,7 +40,7 @@ void scripting::on_frontend_close() {
|
||||
scripting::hud = nullptr;
|
||||
}
|
||||
|
||||
void scripting::load_hud_script(scriptenv senv, std::string packid, fs::path file) {
|
||||
void scripting::load_hud_script(const scriptenv& senv, const std::string& packid, const fs::path& file) {
|
||||
int env = *senv;
|
||||
std::string src = files::read_string(file);
|
||||
logger.info() << "loading script " << file.u8string();
|
||||
|
||||
@@ -17,12 +17,12 @@ namespace scripting {
|
||||
void on_frontend_close();
|
||||
|
||||
/**
|
||||
* Load package-specific hud script
|
||||
* Load package-specific hud script
|
||||
* @param env environment id
|
||||
* @param packid content-pack id
|
||||
* @param file script file path
|
||||
*/
|
||||
void load_hud_script(scriptenv env, std::string packid, fs::path file);
|
||||
void load_hud_script(const scriptenv &env, const std::string &packid, const fs::path &file);
|
||||
}
|
||||
|
||||
#endif // LOGIC_SCRIPTING_SCRIPTING_HUD_HPP_
|
||||
|
||||
Reference in New Issue
Block a user