Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Nov 7, 2020
1 parent b53ccf3 commit 1004096
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation name: "jsmacros-1.16.3-1.2.7-beta-21df5de-dev"
modImplementation name: "jsmacros-1.16.4-1.2.8-dev"

modImplementation name: 'luaj-jse-3.0.2'
include name: 'luaj-jse-3.0.2'
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.3
yarn_mappings=1.16.3+build.1
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.1
loader_version=0.9.1+build.205

# Mod Properties
mod_version = 1.0.8
mod_version = 1.0.9
maven_group = xyz.wagyourtail
archives_base_name = jsmacros-lua

Expand Down
108 changes: 95 additions & 13 deletions src/main/java/xyz/wagyourtail/jsmacroslua/functions/FConsumerLua.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package xyz.wagyourtail.jsmacroslua.functions;

import java.util.List;

import org.luaj.vm2.LuaClosure;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.jse.CoerceJavaToLua;

import org.luaj.vm2.lib.jse.CoerceLuaToJava;
import xyz.wagyourtail.jsmacros.extensionbase.Functions;
import xyz.wagyourtail.jsmacros.extensionbase.IFConsumer;
import xyz.wagyourtail.jsmacros.extensionbase.MethodWrapper;

import java.util.List;

public class FConsumerLua extends Functions implements IFConsumer<LuaClosure, LuaClosure, LuaClosure> {


Expand All @@ -21,9 +22,48 @@ public FConsumerLua(String libName, List<String> exclude) {
}

@Override
public MethodWrapper<Object, Object> autoWrap(LuaClosure c) {
return new MethodWrapper<Object, Object>() {

public MethodWrapper<Object, Object, Object> autoWrap(LuaClosure c) {
return new MethodWrapper<Object, Object, Object>() {

@Override
public Object get() {
return CoerceLuaToJava.coerce(c.call(), Object.class);
}

@Override
public boolean test(Object o) {
return c.call(CoerceJavaToLua.coerce(o)).toboolean();
}

@Override
public Object apply(Object o) {
return CoerceLuaToJava.coerce(c.call(CoerceJavaToLua.coerce(o)), Object.class);
}

@Override
public boolean test(Object o, Object o2) {
return c.call(CoerceJavaToLua.coerce(o), CoerceJavaToLua.coerce(o2)).toboolean();
}

@Override
public Object apply(Object o, Object o2) {
return CoerceLuaToJava.coerce(c.call(CoerceJavaToLua.coerce(o), CoerceJavaToLua.coerce(o2)), Object.class);
}

@Override
public int compare(Object o1, Object o2) {
LuaValue val = c.call(CoerceJavaToLua.coerce(o1), CoerceJavaToLua.coerce(o2));
if (val.isnumber()) {
return val.toint();
}
throw new RuntimeException("could not convert lua value to integer");
}

@Override
public void run() {
c.call();
}

@Override
public void accept(Object arg0) {
c.call(CoerceJavaToLua.coerce(arg0));
Expand All @@ -38,9 +78,51 @@ public void accept(Object arg0, Object arg1) {
}

@Override
public MethodWrapper<Object, Object> autoWrapAsync(LuaClosure c) {
return new MethodWrapper<Object, Object>() {

public MethodWrapper<Object, Object, Object> autoWrapAsync(LuaClosure c) {
return new MethodWrapper<Object, Object, Object>() {

@Override
public Object get() {
return CoerceLuaToJava.coerce(c.call(), Object.class);
}

@Override
public boolean test(Object o) {
return c.call(CoerceJavaToLua.coerce(o)).toboolean();
}

@Override
public Object apply(Object o) {
return CoerceLuaToJava.coerce(c.call(CoerceJavaToLua.coerce(o)), Object.class);
}

@Override
public boolean test(Object o, Object o2) {
return c.call(CoerceJavaToLua.coerce(o), CoerceJavaToLua.coerce(o2)).toboolean();
}

@Override
public Object apply(Object o, Object o2) {
return CoerceLuaToJava.coerce(c.call(CoerceJavaToLua.coerce(o), CoerceJavaToLua.coerce(o2)), Object.class);
}

@Override
public int compare(Object o1, Object o2) {
LuaValue val = c.call(CoerceJavaToLua.coerce(o1), CoerceJavaToLua.coerce(o2));
if (val.isnumber()) {
return val.toint();
}
throw new RuntimeException("could not convert lua value to integer");
}

@Override
public void run() {
Thread t = new Thread(() -> {
c.call();
});
t.start();
}

@Override
public void accept(Object arg0) {
Thread t = new Thread(() -> {
Expand All @@ -61,22 +143,22 @@ public void accept(Object arg0, Object arg1) {
}

@Override
public MethodWrapper<Object, Object> toAsyncBiConsumer(LuaClosure arg0) {
public MethodWrapper<Object, Object, Object> toAsyncBiConsumer(LuaClosure arg0) {
return autoWrapAsync(arg0);
}

@Override
public MethodWrapper<Object, Object> toAsyncConsumer(LuaClosure arg0) {
public MethodWrapper<Object, Object, Object> toAsyncConsumer(LuaClosure arg0) {
return autoWrapAsync(arg0);
}

@Override
public MethodWrapper<Object, Object> toBiConsumer(LuaClosure arg0) {
public MethodWrapper<Object, Object, Object> toBiConsumer(LuaClosure arg0) {
return autoWrap(arg0);
}

@Override
public MethodWrapper<Object, Object> toConsumer(LuaClosure arg0) {
public MethodWrapper<Object, Object, Object> toConsumer(LuaClosure arg0) {
return autoWrap(arg0);
}
}

0 comments on commit 1004096

Please sign in to comment.