Skip to content

Commit

Permalink
Merge pull request #354 from Pieter12345/export_change
Browse files Browse the repository at this point in the history
Made import/export accept an IVar as key.
  • Loading branch information
LadyCailin committed Nov 23, 2015
2 parents d671586 + ea5042e commit c0aadb8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/main/java/com/laytonsmith/core/functions/DataHandling.java
Expand Up @@ -2726,7 +2726,7 @@ public String docs() {

@Override
public ExceptionType[] thrown() {
return new ExceptionType[]{};
return new ExceptionType[]{ExceptionType.IllegalArgumentException};
}

@Override
Expand All @@ -2736,7 +2736,7 @@ public boolean isRestricted() {

@Override
public boolean preResolveVariables() {
return false;
return true;
}

@Override
Expand All @@ -2758,7 +2758,17 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
// return CVoid.VOID;
// } else {
//Mode 2
String key = GetNamespace(args, null, getName(), t);
String key;
if(args.length == 1) {
if(!(args[0] instanceof CString)) {
throw new ConfigRuntimeException(this.getName() + " with 1 argument expects the argument to be a string.",
ExceptionType.IllegalArgumentException, t);
}
key = args[0].val();
} else {
// Handle the deprecated syntax.
key = GetNamespace(args, null, getName(), t);
}
return Globals.GetGlobalConstruct(key);
// }
}
Expand Down Expand Up @@ -2818,7 +2828,7 @@ public String docs() {

@Override
public ExceptionType[] thrown() {
return new ExceptionType[]{ExceptionType.InsufficientArgumentsException};
return new ExceptionType[]{ExceptionType.InsufficientArgumentsException, ExceptionType.IllegalArgumentException};
}

@Override
Expand All @@ -2828,7 +2838,7 @@ public boolean isRestricted() {

@Override
public boolean preResolveVariables() {
return false;
return true;
}

@Override
Expand All @@ -2851,12 +2861,22 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
// throw new ConfigRuntimeException("Expecting a IVariable when only one parameter is specified", ExceptionType.InsufficientArgumentsException, t);
// }
// } else {
String key = GetNamespace(args, args.length - 1, getName(), t);
Construct c = args[args.length - 1];
//We want to store the value contained, not the ivar itself
while (c instanceof IVariable) {
c = environment.getEnv(GlobalEnv.class).GetVarList().get(((IVariable) c).getName(), t).ival();
String key;
if(args.length == 2) {
if(!(args[0] instanceof CString)) {
throw new ConfigRuntimeException(this.getName() + " with 2 arguments expects the first argument to be a string.",
ExceptionType.IllegalArgumentException, t);
}
key = args[0].val();
} else {
// Handle the deprecated syntax.
key = GetNamespace(args, args.length - 1, getName(), t);
}
Construct c = args[args.length - 1];
// //We want to store the value contained, not the ivar itself
// while (c instanceof IVariable) {
// c = environment.getEnv(GlobalEnv.class).GetVarList().get(((IVariable) c).getName(), t).ival();
// }
Globals.SetGlobal(key, c);
// }
return CVoid.VOID;
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/laytonsmith/core/functions/DataHandlingTest.java
Expand Up @@ -339,6 +339,21 @@ public void testExportImportWithProcs2() throws Exception{
+ "msg(_get())", fakePlayer);
verify(fakePlayer).sendMessage("{1, 2}");
}

@Test
public void testExportImportIvarValue() throws Exception{
when(fakePlayer.isOp()).thenReturn(Boolean.TRUE);
SRun("assign(@key, 'key1')"
+ "assign(@value, 'key1Value')"
+ "export(@key, @value)"
+ "msg(import('key1'))", fakePlayer);
verify(fakePlayer).sendMessage("key1Value");
SRun("assign(@key, 'key2')"
+ "assign(@value, 'key2Value')"
+ "export('key2', @value)"
+ "msg(import(@key))", fakePlayer);
verify(fakePlayer).sendMessage("key2Value");
}

@Test(timeout = 10000)
public void testIsBoolean() throws Exception {
Expand Down

0 comments on commit c0aadb8

Please sign in to comment.