Simplify bindings.
This commit is contained in:
@@ -23,6 +23,8 @@ package org.luaj.vm2.lib.jse;
|
|||||||
|
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
import org.luaj.vm2.lib.MathLib;
|
import org.luaj.vm2.lib.MathLib;
|
||||||
|
import org.luaj.vm2.lib.OneArgFunction;
|
||||||
|
import org.luaj.vm2.lib.TwoArgFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Math library implementation for use on JSE platform.
|
* Math library implementation for use on JSE platform.
|
||||||
@@ -35,19 +37,18 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
|
|||||||
public JseMathLib() {}
|
public JseMathLib() {}
|
||||||
|
|
||||||
public LuaValue call(LuaValue arg) {
|
public LuaValue call(LuaValue arg) {
|
||||||
MathLib ml = new MathLib();
|
LuaValue t = super.call(arg);
|
||||||
ml.setfenv(env);
|
bind( t, JseMathLib1.class, new String[] {
|
||||||
LuaValue t = ml.call(arg);
|
|
||||||
bind1( t, new String[] {
|
|
||||||
"acos", "asin", "atan", "cosh",
|
"acos", "asin", "atan", "cosh",
|
||||||
"exp", "log", "log10", "sinh",
|
"exp", "log", "log10", "sinh",
|
||||||
"tanh" } );
|
"tanh" } );
|
||||||
bind2( t, new String[] {
|
bind( t, JseMathLib2.class, new String[] {
|
||||||
"atan2", "pow", } );
|
"atan2", "pow", } );
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LuaValue oncall1(int opcode, LuaValue arg) {
|
public static final class JseMathLib1 extends OneArgFunction {
|
||||||
|
public LuaValue call(LuaValue arg) {
|
||||||
switch ( opcode ) {
|
switch ( opcode ) {
|
||||||
case 0: return valueOf(Math.acos(arg.todouble()));
|
case 0: return valueOf(Math.acos(arg.todouble()));
|
||||||
case 1: return valueOf(Math.asin(arg.todouble()));
|
case 1: return valueOf(Math.asin(arg.todouble()));
|
||||||
@@ -61,14 +62,17 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
|
|||||||
}
|
}
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LuaValue oncall2(int opcode, LuaValue arg1, LuaValue arg2) {
|
public static final class JseMathLib2 extends TwoArgFunction {
|
||||||
|
public LuaValue call(LuaValue arg1, LuaValue arg2) {
|
||||||
switch ( opcode ) {
|
switch ( opcode ) {
|
||||||
case 0: return valueOf(Math.atan2(arg1.todouble(), arg2.todouble()));
|
case 0: return valueOf(Math.atan2(arg1.todouble(), arg2.todouble()));
|
||||||
case 1: return valueOf(Math.pow(arg1.todouble(), arg2.todouble()));
|
case 1: return valueOf(Math.pow(arg1.todouble(), arg2.todouble()));
|
||||||
}
|
}
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Faster, better version of pow() used by arithmetic operator ^ */
|
/** Faster, better version of pow() used by arithmetic operator ^ */
|
||||||
public double dpow_d(double a, double b) {
|
public double dpow_d(double a, double b) {
|
||||||
|
|||||||
Reference in New Issue
Block a user