Skip to content

Commit 3b27bf0

Browse files
committed
update to 0.1.3.20
1 parent 0b25b0a commit 3b27bf0

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

LICENSE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ authors' sake, the GPL requires that modified versions be marked as
4747
changed, so that their problems will not be attributed erroneously to
4848
authors of previous versions.
4949

50-
Some devices are designed to deny users access to install or run
50+
Some devices are designed to deny users accessExpression to install or run
5151
modified versions of the software inside them, although the manufacturer
5252
can do so. This is fundamentally incompatible with the aim of
5353
protecting users' freedom to change the software. The systematic
@@ -237,7 +237,7 @@ works, which are not by their nature extensions of the covered work,
237237
and which are not combined with it such as to form a larger program,
238238
in or on a volume of a storage or distribution medium, is called an
239239
"aggregate" if the compilation and its resulting copyright are not
240-
used to limit the access or legal rights of the compilation's users
240+
used to limit the accessExpression or legal rights of the compilation's users
241241
beyond what the individual works permit. Inclusion of a covered work
242242
in an aggregate does not cause this License to apply to the other
243243
parts of the aggregate.
@@ -263,7 +263,7 @@ in one of these ways:
263263
product that is covered by this License, on a durable physical
264264
medium customarily used for software interchange, for a price no
265265
more than your reasonable cost of physically performing this
266-
conveying of source, or (2) access to copy the
266+
conveying of source, or (2) accessExpression to copy the
267267
Corresponding Source from a network server at no charge.
268268

269269
c) Convey individual copies of the object code with a copy of the
@@ -272,8 +272,8 @@ in one of these ways:
272272
only if you received the object code with such an offer, in accord
273273
with subsection 6b.
274274

275-
d) Convey the object code by offering access from a designated
276-
place (gratis or for a charge), and offer equivalent access to the
275+
d) Convey the object code by offering accessExpression from a designated
276+
place (gratis or for a charge), and offer equivalent accessExpression to the
277277
Corresponding Source in the same way through the same place at no
278278
further charge. You need not require recipients to copy the
279279
Corresponding Source along with the object code. If the place to

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jar {
2525

2626
dependencies {
2727
compile group: 'org.json', name: 'json', version: '20210307'
28-
compileOnly group: 'com.github.kayjamlang', name: 'executor', version: '0.1.3.17-fix4'
28+
compileOnly group: 'com.github.kayjamlang', name: 'executor', version: '0.1.3.20'
2929
testCompile group: 'junit', name: 'junit', version: '4.12'
3030
}

src/main/java/com/github/kayjamlang/executor/json/JSONLibrary.java

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.github.kayjamlang.executor.json;
22

3-
import com.github.kayjamlang.core.Argument;
3+
import com.github.kayjamlang.core.expressions.data.Argument;
44
import com.github.kayjamlang.core.Type;
5+
import com.github.kayjamlang.executor.Context;
56
import com.github.kayjamlang.executor.Executor;
67
import com.github.kayjamlang.executor.libs.Library;
78
import com.github.kayjamlang.executor.libs.main.ArrayClass;
@@ -18,17 +19,6 @@ public class JSONLibrary extends Library {
1819

1920
public JSONLibrary() throws Exception {
2021
classes.put("JSON", new JSONClass());
21-
addFunction(new LibFunction("jsonDecode", (mainContext, context) -> {
22-
String jsonEncoded = (String) context.variables.get("jsonEncoded");
23-
try {
24-
if(jsonEncoded.startsWith("{"))
25-
return decodeObject(mainContext.executor, new JSONObject(jsonEncoded));
26-
return decodeArray(mainContext.executor, new JSONArray(jsonEncoded));
27-
}catch (Exception e){
28-
e.printStackTrace();
29-
return false;
30-
}
31-
}, new Argument(Type.STRING, "jsonEncoded")));
3222
}
3323

3424
public Object decode(Executor executor, Object value) throws Exception {
@@ -42,6 +32,41 @@ else if(value instanceof Number)
4232
return value;
4333
}
4434

35+
public Object encodeMap(Executor executor, MapClass object) throws Exception {
36+
Map<Object, Object> map = object.getMap((Context) object.data.get("ctx"));
37+
38+
JSONObject jsonObject = new JSONObject();
39+
for(Map.Entry<Object, Object> entry: map.entrySet()) {
40+
Object value = entry.getValue();
41+
if(value instanceof MapClass)
42+
value = encodeMap(executor, (MapClass) value);
43+
else if(value instanceof ArrayClass)
44+
value = encodeArray(executor, (ArrayClass) value);
45+
46+
jsonObject.put(entry.getKey().toString(), value);
47+
}
48+
49+
50+
return jsonObject;
51+
}
52+
53+
public Object encodeArray(Executor executor, ArrayClass object) throws Exception {
54+
List<Object> array = object.getVariable((Context) object.data.get("ctx"), "array");
55+
56+
JSONArray jsonArray = new JSONArray();
57+
for(Object value: array) {
58+
if(value instanceof MapClass)
59+
value = encodeMap(executor, (MapClass) value);
60+
else if(value instanceof ArrayClass)
61+
value = encodeArray(executor, (ArrayClass) value);
62+
63+
jsonArray.put(value);
64+
}
65+
66+
67+
return jsonArray;
68+
}
69+
4570
public Object decodeObject(Executor executor, JSONObject object) throws Exception {
4671
Map<Object, Object> map = new HashMap<>();
4772
for(String key: object.keySet())
@@ -64,8 +89,18 @@ public class JSONClass extends LibClass{
6489
public JSONClass() throws Exception {
6590
super("JSON", null);
6691
setCompanion(new LibObject((object -> {
67-
object.addFunction(new LibFunction("decode", (mainContext, context) -> {
68-
String jsonEncoded = (String) context.variables.get("jsonEncoded");
92+
object.addFunction(new LibFunction("encode", Type.STRING, (mainContext, context) -> {
93+
Object value = context.getVariable("jsonEncoded");
94+
if(value instanceof ArrayClass)
95+
return encodeArray(mainContext.executor, (ArrayClass) value);
96+
else if(value instanceof MapClass)
97+
return encodeMap(mainContext.executor, (MapClass) value);
98+
99+
return false;
100+
}, new Argument(Type.ANY, "jsonEncoded")));
101+
102+
object.addFunction(new LibFunction("decode", Type.ANY, (mainContext, context) -> {
103+
String jsonEncoded = context.getVariable("jsonEncoded");
69104
try {
70105
if(jsonEncoded.startsWith("{"))
71106
return decodeObject(mainContext.executor, new JSONObject(jsonEncoded));

0 commit comments

Comments
 (0)