本文整理汇总了Java中org.luaj.vm2.lib.OneArgFunction类的典型用法代码示例。如果您正苦于以下问题:Java OneArgFunction类的具体用法?Java OneArgFunction怎么用?Java OneArgFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OneArgFunction类属于org.luaj.vm2.lib包,在下文中一共展示了OneArgFunction类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ScriptTimedEventManager
import org.luaj.vm2.lib.OneArgFunction; //导入依赖的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: LuaScript
import org.luaj.vm2.lib.OneArgFunction; //导入依赖的package包/类
public LuaScript(final File file) {
mGlobals = MineGlobals.getGlobals();
// Override print function to add custom output
mGlobals.set("print", new OneArgFunction() {
@Override
public LuaValue call(LuaValue luaValue) {
CoreLogger.info(file.getName(), luaValue.tojstring());
return NIL;
}
});
try {
script = mGlobals.load(new FileReader(file), "script");
} catch (IOException ex) {
script = null;
}
}
示例3: parseDialog
import org.luaj.vm2.lib.OneArgFunction; //导入依赖的package包/类
/**
* Creates a new dialog from the given dialog definition.
*
* @param dialogDefinition a dialog definition
*/
public static Dialog parseDialog(LuaTable dialogDefinition) {
HashMap<String, DialogLine> lines = new HashMap<>();
for (int i = 1; i <= dialogDefinition.length(); i++) {
LuaTable line = dialogDefinition.get(i).checktable();
if (line.get(2).isfunction()) {
lines.put(line.get(1).checkjstring(), new DialogLine.CustomCode(
(next) -> line.get(2).invoke(
new OneArgFunction() {
@Override
public LuaValue call(LuaValue arg) {
next.accept(arg.optjstring(null));
return LuaValue.NIL;
}
}
).optjstring(1, null),
line.get(4).opttable(LuaValue.tableOf()).get("delay").optint(0)
));
} else if (line.get(3).istable()) {
// question
lines.put(line.get(1).checkjstring(), new DialogLine.Question(
line.get(2).checkjstring(),
ScriptUtil.toListTableStream(line.get(3).checktable())
.map(LuaValue::checkjstring)
.collect(Collectors.toList()),
line.get(4).opttable(LuaValue.tableOf()).get("delay").optint(0)
));
} else {
lines.put(line.get(1).checkjstring(), new DialogLine.Statement(
line.get(2).checkjstring(),
line.get(3).optjstring(null),
line.get(4).opttable(LuaValue.tableOf()).get("delay").optint(0)
));
}
}
return new Dialog(lines);
}
示例4: getGlobals
import org.luaj.vm2.lib.OneArgFunction; //导入依赖的package包/类
public static Globals getGlobals() {
Globals globals = JsePlatform.standardGlobals();
globals.set("collectgarbage", NIL);
globals.set("dofile", NIL);
globals.set("load", NIL);
globals.set("loadfile", NIL);
globals.set("module", NIL);
globals.set("require", NIL);
globals.set("package", NIL);
globals.set("io", NIL);
globals.set("os", NIL);
globals.set("luajava", NIL);
globals.set("debug", NIL);
globals.set("newproxy", NIL);
globals.set("print", new OneArgFunction() {
@Override
public LuaValue call(LuaValue luaValue) {
System.out.println(luaValue.tojstring());
return NIL;
}
});
globals.set("register_callback", new Functions.RegisterCallback());
return globals;
}
示例5: testOneArgFunction
import org.luaj.vm2.lib.OneArgFunction; //导入依赖的package包/类
public void testOneArgFunction() throws ScriptException {
e.put("x", 25);
e.eval("y = math.sqrt(x)");
Object y = e.get("y");
assertEquals(5, y);
e.put("f", new OneArgFunction() {
public LuaValue call(LuaValue arg) {
return LuaValue.valueOf(arg.toString()+"123");
}
});
Object r = e.eval("return f('abc')");
assertEquals("abc123", r);
}