org.luaj.vm2.lib.OneArgFunction Java Examples
The following examples show how to use
org.luaj.vm2.lib.OneArgFunction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptEngineTests.java From luaj with MIT License | 5 votes |
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); }
Example #2
Source File: SkullWrapper.java From Lukkit with MIT License | 4 votes |
public SkullWrapper(ItemStack skullItem) { this.skull = (skullItem == null) ? new ItemStack(Material.SKULL_ITEM, 1) : skull; this.self = this; // Allows access from setOwner() since this is populate by the function. if (skullItem == null) { this.skull.setDurability((short) 3); this.meta = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM); } else { this.meta = (SkullMeta) this.skull.getItemMeta(); } this.set("setOwner", new OneArgFunction() { @Override public LuaValue call(LuaValue username) { meta.setOwner(username.checkjstring()); return CoerceJavaToLua.coerce(self); } }); this.set("hasOwner", new ZeroArgFunction() { @Override public LuaValue call() { return LuaValue.valueOf(meta.hasOwner()); } }); this.set("getOwner", new ZeroArgFunction() { @Override public LuaValue call() { if (meta.getOwner() == null) { return LuaValue.NIL; } return LuaValue.valueOf(meta.getOwner()); } }); this.set("getItemStack", new ZeroArgFunction() { @Override public LuaValue call() { skull.setItemMeta(meta); return CoerceJavaToLua.coerce(skull); } }); }