fix downloadFile function with waiting for complete

This commit is contained in:
Micah
2021-04-26 10:07:31 -04:00
parent 676e83fe4e
commit 4353741c54

View File

@@ -266,10 +266,14 @@ int removeTag(lua_State* L) {
* Downloads a file from Lua interpreter
*/
int downloadFile(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::addTag");
int n = ghoul::lua::checkArgumentsAndThrow(L, {2, 3}, "lua::addTag");
const std::string& uri = ghoul::lua::value<std::string>(L, 1);
const std::string& savePath = ghoul::lua::value<std::string>(L, 2);
bool waitForComplete = false;
if (n == 3) {
waitForComplete = ghoul::lua::value<bool>(L, 3);
}
lua_settop(L, 0);
LINFOC("OpenSpaceEngine", fmt::format("Downloading file from {}", uri));
@@ -281,6 +285,14 @@ int downloadFile(lua_State* L) {
DownloadManager::FailOnError::Yes,
5
);
if (waitForComplete) {
while (!future->isFinished && future->errorMessage.empty() ) {
//just wait
LTRACEC("OpenSpaceEngine", fmt::format("waiting {}", future->errorMessage));
}
}
if (!future || !future->isFinished) {
return ghoul::lua::luaError(
L,