本文整理汇总了Java中org.luaj.vm2.lib.ThreeArgFunction类的典型用法代码示例。如果您正苦于以下问题:Java ThreeArgFunction类的具体用法?Java ThreeArgFunction怎么用?Java ThreeArgFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThreeArgFunction类属于org.luaj.vm2.lib包,在下文中一共展示了ThreeArgFunction类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ScriptTimedEventManager
import org.luaj.vm2.lib.ThreeArgFunction; //导入依赖的package包/类
public ScriptTimedEventManager(final RpgPlus plugin) {
final TimerComponent timer = plugin.getTimerManager();
set("at", new ThreeArgFunction() {
@Override
public LuaValue call(LuaValue world, LuaValue time, LuaValue callback) {
int id;
if (time.islong()) {
id = timer.addHandler(plugin.getServer().getWorld(world.checkjstring()), time.checklong(), asRunnable(callback));
} else {
id = timer.addHandler(plugin.getServer().getWorld(world.checkjstring()), toTime(time.checkjstring()), asRunnable(callback));
}
return LuaValue.valueOf(id);
}
});
set("off", new OneArgFunction() {
@Override
public LuaValue call(LuaValue luaValue) {
timer.removeHandler(luaValue.checkint());
return LuaValue.NIL;
}
});
}
示例2: LuaClass
import org.luaj.vm2.lib.ThreeArgFunction; //导入依赖的package包/类
public LuaClass(final Class c) {
super(new Object());
this.c = c;
luaTable1();
metatable.rawset("__newindex", new ThreeArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
String s = arg2.tojstring();
try {
Field field = c.getField(s);
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)
&& field.getAnnotation(LuaExclude.class) == null) {
Class<?> type = field.getType();
Object o = LuaConversion.convertToJava(type, arg3);
field.set(null, o);
return NIL;
}
} catch (Exception e) {
if (e instanceof ConversionError)
throw (ConversionError) e;
}
error("No such field: " + s);
return null;
}
});
luaTable3();
metatable.rawset("__tostring", new ZeroArgFunction() {
@Override
public LuaValue call() {
return LuaValue.valueOf("[JClass: " + LuaClass.this.c.getName() + "]");
}
});
metatable.rawset("__metatable", LuaValue.FALSE);
setmetatable(metatable);
}
示例3: testMetatableNewIndex
import org.luaj.vm2.lib.ThreeArgFunction; //导入依赖的package包/类
public void testMetatableNewIndex() {
// empty metatable
LuaValue mt = LuaValue.tableOf();
assertEquals( table, table.setmetatable(mt) );
assertEquals( userdata, userdata.setmetatable(mt) );
LuaBoolean.s_metatable = mt;
LuaFunction.s_metatable = mt;
LuaNil.s_metatable = mt;
LuaNumber.s_metatable = mt;
// LuaString.s_metatable = mt;
LuaThread.s_metatable = mt;
// plain metatable
final LuaValue fallback = LuaValue.tableOf();
LuaValue abc = LuaValue.valueOf("abc");
mt.set( LuaValue.NEWINDEX, fallback );
table.set(2,abc);
userdata.set(3,abc);
LuaValue.NIL.set(4,abc);
LuaValue.TRUE.set(5,abc);
LuaValue.ONE.set(6,abc);
// string.set(7,abc);
function.set(8,abc);
thread.set(9,abc);
assertEquals( abc, fallback.get(2) );
assertEquals( abc, fallback.get(3) );
assertEquals( abc, fallback.get(4) );
assertEquals( abc, fallback.get(5) );
assertEquals( abc, fallback.get(6) );
// assertEquals( abc, StringLib.instance.get(7) );
assertEquals( abc, fallback.get(8) );
assertEquals( abc, fallback.get(9) );
// metatable with function call
mt.set( LuaValue.NEWINDEX, new ThreeArgFunction() {
public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
fallback.rawset(arg2, LuaValue.valueOf( "via-func-"+arg3 ));
return NONE;
}
});
table.set(12,abc);
userdata.set(13,abc);
LuaValue.NIL.set(14,abc);
LuaValue.TRUE.set(15,abc);
LuaValue.ONE.set(16,abc);
// string.set(17,abc);
function.set(18,abc);
thread.set(19,abc);
LuaValue via = LuaValue.valueOf( "via-func-abc" );
assertEquals( via, fallback.get(12) );
assertEquals( via, fallback.get(13) );
assertEquals( via, fallback.get(14) );
assertEquals( via, fallback.get(15) );
assertEquals( via, fallback.get(16) );
// assertEquals( via, StringLib.instance.get(17) );
assertEquals( via, fallback.get(18) );
assertEquals( via, fallback.get(19) );
}