本文整理汇总了Java中org.luaj.vm2.lib.ZeroArgFunction类的典型用法代码示例。如果您正苦于以下问题:Java ZeroArgFunction类的具体用法?Java ZeroArgFunction怎么用?Java ZeroArgFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZeroArgFunction类属于org.luaj.vm2.lib包,在下文中一共展示了ZeroArgFunction类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LuaVM
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的package包/类
LuaVM() {
this.hookfunc = new ZeroArgFunction() {
public LuaValue call() {
System.out.println("script overan resource limits");
// A simple lua error may be caught by the script, but a
// Java Error will pass through to top and stop the script.
throw new Error("Script overran resource limits.");
}
};
this.localState = getLocalCompiler();
}
示例2: LResponse
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的package包/类
LResponse() {
super();
set("header", new ZeroArgFunction() {
@Override
public LuaValue call() {
if (mHeader == null) {
return LuaValue.NIL;
}
return LuaString.valueOf(mHeader);
}
});
set("body", new ZeroArgFunction() {
@Override
public LuaValue call() {
if (mBody == null) {
return LuaValue.NIL;
}
return LuaString.valueOf(mBody);
}
});
set("status", new ZeroArgFunction() {
@Override
public LuaValue call() {
return LuaInteger.valueOf(mStatusCode);
}
});
}
示例3: LObject
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的package包/类
LObject() {
super();
set("type", new ZeroArgFunction() {
@Override
public LuaValue call() {
String className = LObject.this.onObjectClassName();
if (className != null) {
return LuaString.valueOf(className);
} else {
return LuaValue.NIL;
}
}
});
}
示例4: LuaClass
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的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);
}
示例5: LuaPackage
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的package包/类
public LuaPackage(final String path) {
super(new Object());
this.path = path;
LuaTable metatable = new LuaTable();
metatable.rawset("__index", new TwoArgFunction() {
@Override
public LuaValue call(LuaValue arg1, LuaValue arg2) {
if (arg2.checkjstring().equals("class")) {
try {
Class<?> cla = Class.forName(path);
return new LuaClass(cla);
} catch (ClassNotFoundException e) {
throw new LuaError("No such class: " + path);
}
}
String name = path.isEmpty() ? arg2.checkjstring() : path + "." + arg2.checkjstring();
return new LuaPackage(name);
}
});
metatable.rawset("__tostring", new ZeroArgFunction() {
@Override
public LuaValue call() {
if (path.isEmpty()) return LuaValue.valueOf("[JPackage Root]");
return LuaValue.valueOf("[JPackage: " + path + "]");
}
});
metatable.rawset("__metatable", LuaValue.FALSE);
setmetatable(metatable);
}
示例6: setUp
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
eventManager = new ScriptEventManager(new DummySafeInvoker());
callbackInvoked = new AtomicInteger(0);
callback = new ZeroArgFunction() {
@Override
public LuaValue call() {
callbackInvoked.incrementAndGet();
return LuaValue.NONE;
}
};
}
示例7: installQuite
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的package包/类
protected static void installQuite(LuaTable globals) {
globals.set("print", new ZeroArgFunction() {
@Override
public LuaValue call() {
System.out.print("#");
return LuaValue.NONE;
}
});
}
示例8: testFunctionClosureThreadEnv
import org.luaj.vm2.lib.ZeroArgFunction; //导入依赖的package包/类
public void testFunctionClosureThreadEnv() {
// set up suitable environments for execution
LuaValue aaa = LuaValue.valueOf("aaa");
LuaValue eee = LuaValue.valueOf("eee");
final Globals globals = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals();
LuaTable newenv = LuaValue.tableOf( new LuaValue[] {
LuaValue.valueOf("a"), LuaValue.valueOf("aaa"),
LuaValue.valueOf("b"), LuaValue.valueOf("bbb"), } );
LuaTable mt = LuaValue.tableOf( new LuaValue[] { LuaValue.INDEX, globals } );
newenv.setmetatable(mt);
globals.set("a", aaa);
newenv.set("a", eee);
// function tests
{
LuaFunction f = new ZeroArgFunction() { public LuaValue call() { return globals.get("a");}};
assertEquals( aaa, f.call() );
}
// closure tests
{
Prototype p = createPrototype( "return a\n", "closuretester" );
LuaClosure c = new LuaClosure(p, globals);
// Test that a clusure with a custom enviroment uses that environment.
assertEquals( aaa, c.call() );
c = new LuaClosure(p, newenv);
assertEquals( newenv, c.upValues[0].getValue() );
assertEquals( eee, c.call() );
}
}