Refactoring + update some stuff

This commit is contained in:
Federico Cecchetto
2021-06-19 03:40:28 +02:00
parent 833271b7a1
commit 50eb58dfd9
8 changed files with 52 additions and 53 deletions

View File

@ -155,8 +155,7 @@ namespace scripting
return get_return_value();
}
script_value call_script_function(const entity& entity, const std::string& filename,
const std::string& function, const std::vector<script_value>& arguments)
const char* get_function_pos(const std::string& filename, const std::string& function)
{
if (scripting::script_function_table.find(filename) == scripting::script_function_table.end())
{
@ -164,14 +163,18 @@ namespace scripting
};
const auto functions = scripting::script_function_table[filename];
if (functions.find(function) == functions.end())
{
throw std::runtime_error("Function '" + function + "' in file '" + filename + "' not found");
}
const auto pos = functions.at(function);
return functions.at(function);
}
script_value call_script_function(const entity& entity, const std::string& filename,
const std::string& function, const std::vector<script_value>& arguments)
{
const auto pos = get_function_pos(filename, function);
return exec_ent_thread(entity, pos, arguments);
}

View File

@ -71,6 +71,19 @@ namespace scripting
}
}
std::string find_token(unsigned int id)
{
for (const auto& token : token_map)
{
if (token.second == id)
{
return token.first;
}
}
return {};
}
int find_token_id(const std::string& name)
{
const auto result = token_map.find(name);

View File

@ -12,4 +12,5 @@ namespace scripting
script_function find_function(const std::string& name, const bool prefer_global);
int find_token_id(const std::string& name);
std::string find_token(unsigned int id);
}