当前位置: 首页>>代码示例>>Java>>正文


Java ThreeArgFunction类代码示例

本文整理汇总了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;
        }
    });
}
 
开发者ID:leMaik,项目名称:RpgPlus,代码行数:25,代码来源:ScriptTimedEventManager.java

示例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);
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:41,代码来源:LuaClass.java

示例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) );
	}
 
开发者ID:gnosygnu,项目名称:luaj_xowa,代码行数:60,代码来源:MetatableTest.java


注:本文中的org.luaj.vm2.lib.ThreeArgFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。