diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java index 4f14e7b14e02db035475251d1568b1de228056b8..f00b510ec41d04dc1eb86bce7076a6c0e8cb5ee8 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java @@ -30,14 +30,21 @@ import com.oracle.truffle.r.library.fastrGrid.device.GridDevice.DeviceCloseExcep import com.oracle.truffle.r.library.fastrGrid.device.awt.BufferedJFrameDevice; import com.oracle.truffle.r.library.fastrGrid.device.awt.JFrameDevice; import com.oracle.truffle.r.library.fastrGrid.graphics.RGridGraphicsAdapter; +import com.oracle.truffle.r.runtime.RCaller; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; +import com.oracle.truffle.r.runtime.RInternalCode; +import com.oracle.truffle.r.runtime.context.RContext; +import com.oracle.truffle.r.runtime.data.RFunction; +import com.oracle.truffle.r.runtime.env.REnvironment; /** * Encapsulated the access to the global grid state. */ public final class GridContext { private static final GridContext INSTANCE = new GridContext(); + + private RInternalCode internalCode; private final GridState gridState = new GridState(); /** * This list should correspond to the names inside {@code .Devices} variable in R. @@ -100,6 +107,17 @@ public final class GridContext { } } + /** + * Runs arbitrary function from 'fastrGrid.R' file and returns its result. + */ + public Object evalInternalRFunction(String functionName, Object... args) { + if (internalCode == null) { + internalCode = RInternalCode.lookup(RContext.getInstance(), "grid", RInternalCode.loadSourceRelativeTo(LInitGrid.class, "fastrGrid.R")); + } + RFunction redrawAll = internalCode.lookupFunction(functionName); + return RContext.getEngine().evalFunction(redrawAll, REnvironment.baseEnv().getFrame(), RCaller.topLevel, null, args); + } + private static final class DeviceAndState { final GridDevice device; final GridDeviceState state;