Skip to content
This repository was archived by the owner on Nov 4, 2020. It is now read-only.

Commit 10035cb

Browse files
committed
Merge pull request #17 from Lothar-Tradescape/global_state
Allow scripts to remember state across invocations.
2 parents 305a0d2 + 140a398 commit 10035cb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/org/eclipsescript/scriptobjects/Runtime.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.eclipsescript.scriptobjects;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
36
import org.eclipse.core.resources.IContainer;
47
import org.eclipse.core.resources.IFile;
58
import org.eclipse.core.resources.WorkspaceJob;
@@ -22,6 +25,7 @@
2225
*/
2326
public class Runtime {
2427

28+
private static final Map<String, Object> globals = new HashMap<String, Object>();
2529
private final IScriptRuntime scriptRuntime;
2630

2731
public Runtime(IScriptRuntime scriptRuntime) {
@@ -45,6 +49,10 @@ public void exit() {
4549
scriptRuntime.exitRunningScript();
4650
}
4751

52+
public synchronized Object getGlobal(String key) {
53+
return globals.get(key);
54+
}
55+
4856
public Shell getShell() {
4957
return EclipseUtils.getWindowShell();
5058
}
@@ -72,6 +80,10 @@ public void include(Object... includes) throws Exception {
7280
}
7381
}
7482

83+
public synchronized void putGlobal(String key, Object value) {
84+
globals.put(key, value);
85+
}
86+
7587
public void schedule(final Object objectToSchedule) {
7688
final IJobRunnable runnable = scriptRuntime.adaptTo(objectToSchedule, IJobRunnable.class);
7789
if (runnable == null)

0 commit comments

Comments
 (0)