use of org.cafebabepy.runtime.PyObjectScope in project cafebabepy by cafebabepy.
the class PyInterpretFunctionObject method call.
@Override
public PyObject call(PyObject... args) {
PyObject lexicalContext = new PyLexicalScopeProxyObject(this.context);
PyObjectScope scope = lexicalContext.getScope();
this.runtime.getattrOptional(this.args, "args").ifPresent(argslist -> this.runtime.iterIndex(argslist, (a, i) -> {
PyObject arg = this.runtime.getattr(a, "arg");
scope.put(arg.toJava(String.class), args[i]);
}));
return evaluator.eval(lexicalContext, body);
}
use of org.cafebabepy.runtime.PyObjectScope in project cafebabepy by cafebabepy.
the class PyObjectType method getFromParent.
public Optional<PyObject> getFromParent(PyObject object, String name) {
Optional<PyObjectScope> parentOpt = object.getScope().getParent();
while (parentOpt.isPresent()) {
PyObjectScope parent = parentOpt.get();
Optional<PyObject> result = parent.get(name);
if (result.isPresent()) {
return result;
}
parentOpt = parent.getParent();
}
return Optional.empty();
}
Aggregations