/*
* Created by Andrey Cherkashin (acherkashin)
* http://acherkashin.me
*
* License
* Copyright (c) 2015 Andrey Cherkashin
* The project released under the MIT license: http://opensource.org/licenses/MIT
*/
package ragefist.core.environment;
import com.juniform.JUniformObject;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import ragefist.core.Processor;
import ragefist.core.ProcessorTask;
import ragefist.core.util.FormatTools;
/**
* EnvironmentRemoteCallResultTask is a task that unpauses paused coroutine in
* lua environment and returns the data into it
* @author acherkashin
*/
public class EnvironmentCallResultTask extends ProcessorTask
{
private final EnvironmentProcessor _initiator;
private final int _initiatorTaskId;
public EnvironmentCallResultTask(EnvironmentProcessor initiator, int initiatorTaskId) {
super();
_initiator = initiator;
_initiatorTaskId = initiatorTaskId;
}
@Override
protected boolean _executeImpl(Processor processor) {
ProcessorTask parentTask = this.getParentTask();
LuaValue value = LuaValue.NIL;
if (parentTask.getData() != null) {
value = FormatTools.fromJUniformObjectToLuaValue((JUniformObject)parentTask.getData());
}
EnvironmentCallTask finishTask = new EnvironmentCallTask(
"Processor.unpauseTask(args[1], args[2])",
LuaTable.listOf(new LuaValue[] { LuaValue.valueOf(_initiatorTaskId), value })
);
_initiator.addTask(finishTask);
return true;
}
}