Skip to content

Commit

Permalink
new isbpl
Browse files Browse the repository at this point in the history
  • Loading branch information
TudbuT committed May 23, 2022
1 parent d64cc1c commit 9c3f02e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/tudbut/mod/polyfire/utils/isbpl/ISBPL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,14 @@ public ISBPLObject toISBPL(Class<?> clazz) {
for(Class<?> c : interfaces) {
type.superTypes.add(toISBPL(c).type);
}
for (Class<?> subclass : clazz.getDeclaredClasses()) {
addFunction(type, subclass.getSimpleName(), stack -> {
if(debug)
ISBPL.gErrorStream.println("Java GetSubclass: " + subclass.getName());
stack.pop();
stack.push(toISBPL(subclass));
});
}
if (clazz.isEnum()) {
for (Object o : clazz.getEnumConstants()) {
String name = PolyFire.obfMap.get(clazz.getName().replaceAll("\\.", "/") + "/" + o.toString(), o.toString());
Expand Down Expand Up @@ -1352,6 +1360,11 @@ public Object fromISBPL(ISBPLObject o, Class<?> expectedType) {
if(expectedType == byte.class)
return (byte) o.toLong();
}
if(expectedType == Runnable.class) {
return (Runnable) () -> {
((ISBPLCallable) o.object).call(new ISBPLStack<>());
};
}
if(!expectedType.isAssignableFrom(o.object.getClass()))
typeError(o.type.name, expectedType.getName());
return o.object;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/tudbut/mod/polyfire/utils/isbpl/ISBPL.java.original
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,14 @@ public class ISBPL {
for(Class<?> c : interfaces) {
type.superTypes.add(toISBPL(c).type);
}
for (Class<?> subclass : clazz.getDeclaredClasses()) {
addFunction(type, subclass.getSimpleName(), stack -> {
if(debug)
ISBPL.gErrorStream.println("Java GetSubclass: " + subclass.getName());
stack.pop();
stack.push(toISBPL(subclass));
});
}
if (clazz.isEnum()) {
for (Object o : clazz.getEnumConstants()) {
addFunction(type, o.toString(), stack -> {
Expand Down Expand Up @@ -1342,6 +1350,11 @@ public class ISBPL {
if(expectedType == byte.class)
return (byte) o.toLong();
}
if(expectedType == Runnable.class) {
return (Runnable) () -> {
((ISBPLCallable) o.object).call(new ISBPLStack<>());
};
}
if(!expectedType.isAssignableFrom(o.object.getClass()))
typeError(o.type.name, expectedType.getName());
return o.object;
Expand Down

0 comments on commit 9c3f02e

Please sign in to comment.