Skip to content

Commit fb30b2f

Browse files
committed
Config saving to other file.
1 parent 8e0e376 commit fb30b2f

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.byteskript</groupId>
88
<artifactId>byteskript</artifactId>
9-
<version>1.0.19</version>
9+
<version>1.0.20</version>
1010
<name>ByteSkript</name>
1111
<description>A compiled JVM implementation of the Skript language.</description>
1212

@@ -113,11 +113,6 @@
113113
<version>4.13.2</version>
114114
<scope>test</scope>
115115
</dependency>
116-
<dependency>
117-
<groupId>org.panteleyev</groupId>
118-
<artifactId>jpackage-maven-plugin</artifactId>
119-
<version>1.5.1</version>
120-
</dependency>
121116
</dependencies>
122117

123118
</project>

src/main/java/org/byteskript/skript/lang/syntax/config/SaveConfigEffect.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.byteskript.skript.lang.element.StandardElements;
1515
import org.byteskript.skript.runtime.config.ConfigMap;
1616

17+
import java.util.Map;
18+
1719
@Documentation(
1820
name = "Save Config",
1921
description = """
@@ -29,21 +31,23 @@
2931
public class SaveConfigEffect extends Effect {
3032

3133
public SaveConfigEffect() {
32-
super(SkriptLangSpec.LIBRARY, StandardElements.EFFECT, "save config %Object%");
33-
}
34-
35-
@Override
36-
public void preCompile(Context context, Pattern.Match match) throws Throwable {
37-
final MethodBuilder method = context.getMethod();
38-
method.writeCode(WriteInstruction.getField(System.class.getField("out")));
39-
super.preCompile(context, match);
34+
super(SkriptLangSpec.LIBRARY, StandardElements.EFFECT, "save config %Object% to %Object%", "save config %Object%");
4035
}
4136

4237
@Override
4338
public void compile(Context context, Pattern.Match match) throws Throwable {
4439
final MethodBuilder method = context.getMethod();
45-
method.writeCode(WriteInstruction.cast(CommonTypes.CONFIG));
46-
method.writeCode(WriteInstruction.invokeVirtual(ConfigMap.class.getMethod("save")));
40+
if (match.matchedPattern == 1) {
41+
method.writeCode(WriteInstruction.cast(CommonTypes.CONFIG));
42+
method.writeCode(WriteInstruction.invokeVirtual(ConfigMap.class.getMethod("save")));
43+
} else {
44+
method.writeCode(WriteInstruction.cast(CommonTypes.CONFIG)); // orig, new
45+
method.writeCode(WriteInstruction.duplicateDrop2()); // new, orig, new
46+
method.writeCode(WriteInstruction.swap()); // new, new, orig
47+
method.writeCode(WriteInstruction.cast(CommonTypes.CONFIG)); // new, new, orig
48+
method.writeCode(WriteInstruction.invokeVirtual(ConfigMap.class.getMethod("putAll", Map.class))); // new
49+
method.writeCode(WriteInstruction.invokeVirtual(ConfigMap.class.getMethod("save")));
50+
}
4751
context.setState(CompileState.CODE_BODY);
4852
}
4953

src/test/resources/configs.bsk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@ function test:
1010
set "thing" from {conf} to "hello there!"
1111
assert "thing" from {conf} is "hello there!"
1212
delete hello.csk
13+
set {conf2} to a new config
14+
add "key: bean" to {conf2}
15+
assert "key" from {conf2} is "bean"
16+
save config {conf2} to hello.csk
17+
set {conf} to hello.csk
18+
assert "key" from {conf} is "bean"
19+
delete hello.csk
20+
21+
1322

0 commit comments

Comments
 (0)