コード例 #1
0
ファイル: HookHandler.java プロジェクト: Runsafe/EventEngine
  @Override
  public void OnPlayerDamage(IPlayer player, RunsafeEntityDamageEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.PLAYER_DAMAGE);

    if (hooks != null) {
      IWorld damageWorld = player.getWorld();

      LuaString playerName = LuaValue.valueOf(player.getName());
      LuaString damageCause = LuaValue.valueOf(event.getCause().name());
      LuaValue damage = LuaValue.valueOf(event.getDamage());

      for (Hook hook : hooks) {
        IWorld world = hook.getWorld();
        if (world == null || !world.isWorld(damageWorld)) return;

        LuaTable table = new LuaTable();
        table.set("player", playerName);
        table.set("playerHealth", player.getHealth());
        table.set("playerMaxHealth", player.getMaxHealth());
        table.set("damage", damage);
        table.set("cause", damageCause);

        hook.execute(table);
      }
    }
  }
コード例 #2
0
ファイル: Utils.java プロジェクト: doomstal/tmw-bot
 public static void copyTable(LuaValue src, LuaValue dst) {
   LuaValue k = LuaValue.NIL;
   while (true) {
     Varargs n = src.next(k);
     if ((k = n.arg1()).isnil()) break;
     dst.set(k, n.arg(2));
   }
 }
コード例 #3
0
ファイル: Utils.java プロジェクト: doomstal/tmw-bot
 public static void clearTable(LuaValue table) {
   LuaValue k = LuaValue.NIL;
   while (true) {
     Varargs n = table.next(k);
     if ((k = n.arg1()).isnil()) break;
     table.set(k, LuaValue.NIL);
   }
 }
コード例 #4
0
ファイル: JseMathLib.java プロジェクト: jameszhan/luaj
 public LuaValue call(LuaValue arg1, LuaValue arg2) {
   switch (opcode) {
     case 0:
       return valueOf(Math.atan2(arg1.checkdouble(), arg2.checkdouble()));
     case 1:
       return valueOf(Math.pow(arg1.checkdouble(), arg2.checkdouble()));
   }
   return NIL;
 }
コード例 #5
0
ファイル: OsLibTest.java プロジェクト: MarkSill/social
 public void testJseOsGetenvForSystemProperties() {
   System.setProperty("test.key.foo", "test.value.bar");
   LuaValue key = LuaValue.valueOf("test.key.foo");
   LuaValue value = LuaValue.valueOf("test.value.bar");
   LuaValue jse_value = jse_lib.get("getenv").call(key);
   LuaValue jme_value = jme_lib.get("getenv").call(key);
   assertEquals(value, jse_value);
   assertEquals(value, jme_value);
 }
コード例 #6
0
ファイル: LuaViewUtil.java プロジェクト: alibaba/LuaViewSDK
 /**
  * get text of given value
  *
  * @param inputValue
  * @return
  */
 public static CharSequence getText(LuaValue inputValue) {
   final LuaValue result = (inputValue != null && !inputValue.isnil()) ? inputValue : LuaValue.NIL;
   if (result instanceof UDSpannableString) {
     return ((UDSpannableString) result).getSpannableStringBuilder();
   } else if (result instanceof UDUnicode) {
     return result.toString();
   } else {
     return result.optjstring("");
   }
 }
コード例 #7
0
 public LuaValue get(LuaValue key) {
   if (key.equals(LENGTH)) return valueOf(Array.getLength(m_instance));
   if (key.isint()) {
     int i = key.toint() - 1;
     return i >= 0 && i < Array.getLength(m_instance)
         ? CoerceJavaToLua.coerce(Array.get(m_instance, key.toint() - 1))
         : NIL;
   }
   return super.get(key);
 }
コード例 #8
0
 public void set(LuaValue key, LuaValue value) {
   if (key.isint()) {
     int i = key.toint() - 1;
     if (i >= 0 && i < Array.getLength(m_instance))
       Array.set(
           m_instance, i, CoerceLuaToJava.coerce(value, m_instance.getClass().getComponentType()));
     else if (m_metatable == null || !settable(this, key, value))
       error("array index out of bounds");
   } else super.set(key, value);
 }
コード例 #9
0
 public LuaValue call(String name, Object arg) throws LuaError {
   String luaClassName = lua_getLuaClassName(arg.getClass());
   try {
     pL.eval(String.format("__metatable = %s.getMetaTableForUserdata()", luaClassName));
   } catch (ScriptException ex) {
     throw new RuntimeException("<LuabindObject.call> Exception: " + ex.getMessage(), ex);
   }
   LuaValue metatable = ((LuaValue) pL.get("__metatable"));
   return val.get(name).call(LuaValue.userdataOf(arg, metatable));
 }
コード例 #10
0
  public static <T extends Number> T LuaPopNumberFieldFromTable(LuaTable L, final String key) {
    LuaValue val = L.get(key);

    // check that the variable is the correct type. If it is not throw an
    // exception
    if (!(val instanceof LuaString)) {
      String err = "<LuaPopNumberFieldFromTable> Cannot retrieve: ";
      throw new RuntimeException(err + key);
    }

    // grab the data
    return (T) new Double(val.todouble());
  }
コード例 #11
0
 public LuaValue call(String name, Object arg1, Object arg2) throws LuaError {
   String luaClassName1 = lua_getLuaClassName(arg1.getClass());
   String luaClassName2 = lua_getLuaClassName(arg2.getClass());
   try {
     pL.eval(String.format("__metatable1=%s.getMetaTableForUserdata()", luaClassName1));
     pL.eval(String.format("__metatable2=%s.getMetaTableForUserdata()", luaClassName2));
   } catch (ScriptException ex) {
     throw new RuntimeException("<LuabindObject.call> Exception: " + ex.getMessage(), ex);
   }
   LuaValue metatable1 = ((LuaValue) pL.get("__metatable1")).getmetatable();
   LuaValue metatable2 = ((LuaValue) pL.get("__metatable2")).getmetatable();
   return val.get(name)
       .call(LuaValue.userdataOf(arg1, metatable1), LuaValue.userdataOf(arg2, metatable2));
 }
コード例 #12
0
ファイル: ModuleHighFive.java プロジェクト: Cazzar/Shocky
    @Override
    public LuaValue call(LuaValue arg1, LuaValue arg2) {
      String nick1 = arg1.checkjstring().toLowerCase();
      String nick2 = arg2.checkjstring().toLowerCase();

      if (nick1.compareTo(nick2) > 0) {
        String temp = nick1;
        nick1 = nick2;
        nick2 = temp;
      }

      String key = nick1 + ' ' + nick2;
      return valueOf(config.exists(key) ? config.getInt(key) : 0);
    }
コード例 #13
0
ファイル: HookHandler.java プロジェクト: Runsafe/EventEngine
  @SuppressWarnings("unchecked")
  @Override
  public void OnPlayerCustomEvent(RunsafeCustomEvent event) {
    HookType type = null;
    String eventType = event.getEvent();

    if (eventType.equals("region.enter")) type = HookType.REGION_ENTER;
    else if (eventType.equals("region.leave")) type = HookType.REGION_LEAVE;

    if (type != null) {
      List<Hook> hooks = HookHandler.getHooks(type);

      if (hooks != null) {
        for (final Hook hook : hooks) {
          Map<String, String> data = (Map<String, String>) event.getData();
          if (((String) hook.getData())
              .equalsIgnoreCase(String.format("%s-%s", data.get("world"), data.get("region")))) {
            final LuaTable table = new LuaTable();
            table.set("player", LuaValue.valueOf(event.getPlayer().getName()));

            scheduler.runNow(
                new Runnable() {
                  @Override
                  public void run() {
                    hook.execute(table);
                  }
                });
          }
        }
      }
    }
  }
コード例 #14
0
ファイル: FuncState.java プロジェクト: MarkSill/social
 int numberK(LuaValue r) {
   if (r instanceof LuaDouble) {
     double d = r.todouble();
     int i = (int) d;
     if (d == (double) i) r = LuaInteger.valueOf(i);
   }
   return this.addk(r);
 }
コード例 #15
0
ファイル: HookHandler.java プロジェクト: Runsafe/EventEngine
  @Override
  public void OnPlayerLeftClick(RunsafePlayerClickEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.LEFT_CLICK_BLOCK);

    if (hooks != null) {
      IBlock block = event.getBlock();
      Item material = block.getMaterial();
      ILocation blockLocation = block.getLocation();
      String blockWorldName = blockLocation.getWorld().getName();
      String playerName = event.getPlayer().getName();
      for (Hook hook : hooks) {
        IWorld world = hook.getWorld();
        if (world != null && !blockWorldName.equals(world.getName())) return;

        LuaTable table = new LuaTable();
        table.set("player", LuaValue.valueOf(playerName));
        table.set("world", LuaValue.valueOf(blockWorldName));
        table.set("x", LuaValue.valueOf(blockLocation.getBlockX()));
        table.set("y", LuaValue.valueOf(blockLocation.getBlockY()));
        table.set("z", LuaValue.valueOf(blockLocation.getBlockZ()));
        table.set("blockID", LuaValue.valueOf(material.getItemID()));
        table.set("blockData", LuaValue.valueOf(material.getData()));

        hook.execute(table);
      }
    }
  }
コード例 #16
0
ファイル: HookHandler.java プロジェクト: Runsafe/EventEngine
  @Override
  public boolean OnBlockBreak(IPlayer player, IBlock block) {
    List<Hook> hooks = HookHandler.getHooks(HookType.BLOCK_BREAK);

    if (hooks != null) {
      ILocation blockLocation = block.getLocation();
      String blockWorld = blockLocation.getWorld().getName();
      for (Hook hook : hooks) {
        IWorld world = hook.getWorld();
        if (world != null && !blockWorld.equals(world.getName())) return true;

        LuaTable table = new LuaTable();
        if (player != null) table.set("player", LuaValue.valueOf(player.getName()));

        table.set("world", LuaValue.valueOf(blockWorld));
        table.set("x", LuaValue.valueOf(blockLocation.getBlockX()));
        table.set("y", LuaValue.valueOf(blockLocation.getBlockY()));
        table.set("z", LuaValue.valueOf(blockLocation.getBlockZ()));
        table.set("blockID", LuaValue.valueOf(block.getMaterial().getItemID()));
        table.set("blockData", LuaValue.valueOf(((RunsafeBlock) block).getData()));

        hook.execute(table);
      }
    }
    return true;
  }
コード例 #17
0
ファイル: OsLibTest.java プロジェクト: MarkSill/social
 public void testJseOsGetenvForEnvVariables() {
   LuaValue USER = LuaValue.valueOf("USER");
   LuaValue jse_user = jse_lib.get("getenv").call(USER);
   LuaValue jme_user = jme_lib.get("getenv").call(USER);
   assertFalse(jse_user.isnil());
   assertTrue(jme_user.isnil());
   System.out.println("User: " + jse_user);
 }
コード例 #18
0
 @Override
 public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
   return new BaseVarArgUICreator(env.checkglobals(), metaTable) {
     @Override
     public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) {
       //                return new LVRecyclerView(globals, metaTable, varargs, null);
       return LVRecyclerView.createVerticalView(globals, metaTable, varargs, null);
     }
   };
 }
コード例 #19
0
ファイル: FuncState.java プロジェクト: MarkSill/social
 boolean constfolding(int op, expdesc e1, expdesc e2) {
   LuaValue v1, v2, r;
   if (!e1.isnumeral() || !e2.isnumeral()) return false;
   if ((op == OP_DIV || op == OP_MOD) && e2.u.nval().eq_b(LuaValue.ZERO))
     return false; /* do not attempt to divide by 0 */
   v1 = e1.u.nval();
   v2 = e2.u.nval();
   switch (op) {
     case OP_ADD:
       r = v1.add(v2);
       break;
     case OP_SUB:
       r = v1.sub(v2);
       break;
     case OP_MUL:
       r = v1.mul(v2);
       break;
     case OP_DIV:
       r = v1.div(v2);
       break;
     case OP_MOD:
       r = v1.mod(v2);
       break;
     case OP_POW:
       r = v1.pow(v2);
       break;
     case OP_UNM:
       r = v1.neg();
       break;
     case OP_LEN:
       // r = v1.len();
       // break;
       return false; /* no constant folding for 'len' */
     default:
       _assert(false);
       r = null;
       break;
   }
   if (Double.isNaN(r.todouble())) return false; /* do not attempt to produce NaN */
   e1.u.setNval(r);
   return true;
 }
コード例 #20
0
ファイル: HookHandler.java プロジェクト: Runsafe/EventEngine
  @Override
  public void OnPlayerChatEvent(RunsafePlayerChatEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.CHAT_MESSAGE);

    if (hooks != null) {
      IPlayer player = event.getPlayer();
      IWorld playerWorld = player.getWorld();

      if (playerWorld == null) return;

      for (Hook hook : hooks) {
        if (hook.getWorld().isWorld(player.getWorld())) {
          LuaTable table = new LuaTable();
          table.set("player", LuaValue.valueOf(player.getName()));
          table.set("message", LuaValue.valueOf(event.getMessage()));

          hook.execute(table);
        }
      }
    }
  }
コード例 #21
0
 @Override
 public LuaValue call(LuaValue pnts, LuaValue p) {
   Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
   if (!token.isSelfOrTrusted()) {
     throw new LuaError(
         new ParserException(
             I18N.getText("macro.function.general.noPerm", "token.movedOverPoints")));
   }
   String points = pnts.checkjstring();
   if (p.isnil()) {
     Path<?> path = token.getToken().getLastPath();
     return LuaConverters.fromJson(
         TokenMoveFunctions.pathPointsToJSONArray(
             TokenMoveFunctions.crossedPoints(
                 zone, token.getToken(), points, TokenMoveFunctions.getLastPathList(path, true))));
   } else {
     String jsonPath = ObjectUtils.toString(LuaConverters.toJson(p));
     return LuaConverters.fromJson(
         TokenMoveFunctions.pathPointsToJSONArray(
             TokenMoveFunctions.crossedPoints(zone, token.getToken(), points, jsonPath)));
   }
 }
コード例 #22
0
ファイル: Lua.java プロジェクト: Xemiru/Undertailor
  /**
   * Returns the given {@link LuaValue} as the appropriate type of {@link LuaObjectValue}, directed
   * by the provided {@link LuaObjectMeta} type.
   *
   * <p>If the provided value is not of the appropriate type, a {@link LuaError} is raised.
   *
   * @param value the LuaValue to check
   * @param clazz the target LuaObjectMeta type to check with
   * @return the appropriately typed LuaValue as a LuaObjectValue
   */
  public static <T> LuaObjectValue<T> checkType(
      LuaValue value, Class<? extends LuaObjectMeta> clazz) {
    LuaObjectMeta meta = Lua.getMeta(clazz);
    if (meta == null) {
      throw new IllegalArgumentException(
          "Meta class " + clazz.getSimpleName() + " isn't registered");
    }

    if (value instanceof LuaObjectValue) {
      LuaObjectValue<?> objectValue = ((LuaObjectValue<?>) value);
      if (meta.getTargetObjectClass().isInstance(objectValue.getObject())) {
        return (LuaObjectValue<T>) objectValue;
      }
    }

    throw new LuaError(String.format(INVALID_TYPE_MSG, meta.getTypeName(), value.typename()));
  }
コード例 #23
0
 @Override
 public Varargs invoke(Varargs args) {
   LuaValue key = args.arg(2);
   Varargs newargs = varargsOf(args.arg(1), args.arg(3));
   LuaValue func = metatable.get(key);
   if (func.isfunction()) { // 函数调用
     func.invoke(newargs);
   } else {
     LogUtil.d("[LuaView error]", "property not fount :", key.toString());
   }
   return NONE;
 }
コード例 #24
0
ファイル: JseMathLib.java プロジェクト: jameszhan/luaj
 public LuaValue call(LuaValue arg) {
   switch (opcode) {
     case 0:
       return valueOf(Math.acos(arg.checkdouble()));
     case 1:
       return valueOf(Math.asin(arg.checkdouble()));
     case 2:
       return valueOf(Math.atan(arg.checkdouble()));
     case 3:
       return valueOf(Math.cosh(arg.checkdouble()));
     case 4:
       return valueOf(Math.exp(arg.checkdouble()));
     case 5:
       return valueOf(Math.log(arg.checkdouble()));
     case 6:
       return valueOf(Math.log10(arg.checkdouble()));
     case 7:
       return valueOf(Math.sinh(arg.checkdouble()));
     case 8:
       return valueOf(Math.tanh(arg.checkdouble()));
   }
   return NIL;
 }
コード例 #25
0
ファイル: HookHandler.java プロジェクト: Runsafe/EventEngine
  @Override
  public void OnPlayerDeathEvent(RunsafePlayerDeathEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.PLAYER_DEATH);

    if (hooks != null) {
      IPlayer player = event.getEntity();

      for (Hook hook : hooks) {
        IWorld hookWorld = hook.getWorld();
        if (hookWorld.isWorld(player.getWorld())) {
          LuaTable table = new LuaTable();
          table.set("player", LuaValue.valueOf(player.getName()));

          hook.execute(table);
        }
      }
    }
  }
コード例 #26
0
ファイル: Encode.java プロジェクト: MalukuSeito/maptool
 @Override
 public LuaValue invoke(Varargs args) {
   LuaValue arg1 = args.arg(1);
   LuaValue arg2 = args.arg(2);
   List<String> vals = new ArrayList<String>();
   for (int i = 3; !args.arg(i).isnil(); i++) {
     vals.add(args.arg(i).checkjstring());
   }
   return LuaValue.valueOf(
       LuaConverters.encode(
           arg1.checkjstring(),
           arg2.isboolean() ? arg2.toboolean() : true,
           vals.toArray(new String[0])));
 }
コード例 #27
0
ファイル: GuiScreen.java プロジェクト: nocaremc/game
  @Override
  public void handleInput(IGuiMouseState gui) {
    if ((gui.getState() == ButtonState.CLICKED)) {
      // Associate lua action file for this guiscreen with the lua engine
      App.getLua().get("dofile").call(LuaValue.valueOf(resourcePath + "buttonActions.lua"));

      // The function we call for clicks, within lua fine
      LuaValue clickAction = App.getLua().get("returnClick");

      // Value we pass to lua function. Button ID in this case
      LuaValue returnValue = clickAction.call(LuaValue.valueOf(((GuiButton) gui).getID()));

      // Set the button's state to none/null so we don't grab it again
      ((GuiButton) gui).setState(ButtonState.NONE);

      // String value of returnValue
      String sReturnValue = returnValue.tojstring();

      // Have App send the command to the proper place
      App.delegateLuaActionResponse(sReturnValue);
    }
  }
コード例 #28
0
ファイル: HookHandler.java プロジェクト: Runsafe/EventEngine
  @Override
  public void OnPlayerInteractEvent(RunsafePlayerInteractEvent event) {
    debug.debugFine("Interact event detected");
    List<Hook> hooks = HookHandler.getHooks(HookType.INTERACT);

    if (hooks != null) {
      debug.debugFine("Hooks not null");
      for (Hook hook : hooks) {
        debug.debugFine("Processing hook...");
        IBlock block = event.getBlock();
        if (hook.getData() != null)
          if (block == null || block.getMaterial().getItemID() != (Integer) hook.getData())
            continue;

        debug.debugFine("Block is not null");

        IWorld hookWorld = hook.getWorld();
        ILocation location = block.getLocation();
        if (hookWorld == null) {
          debug.debugFine("Hook world is null, using location");
          if (location.getWorld().getName().equals(hook.getLocation().getWorld().getName())) {
            debug.debugFine("Correct world!");
            if (location.distance(hook.getLocation()) < 1) {
              debug.debugFine("Distance is less than 1");
              LuaTable table = new LuaTable();
              if (event.getPlayer() != null)
                table.set("player", LuaValue.valueOf(event.getPlayer().getName()));

              table.set("x", LuaValue.valueOf(location.getBlockX()));
              table.set("y", LuaValue.valueOf(location.getBlockY()));
              table.set("z", LuaValue.valueOf(location.getBlockZ()));
              table.set("blockID", LuaValue.valueOf(block.getMaterial().getItemID()));
              table.set("blockData", LuaValue.valueOf((block).getData()));

              hook.execute(table);
            }
          }
        } else if (hookWorld.getName().equals(block.getWorld().getName())) {
          debug.debugFine("Hook world is null, sending location data");
          LuaTable table = new LuaTable();
          if (event.getPlayer() != null)
            table.set("player", LuaValue.valueOf(event.getPlayer().getName()));

          table.set("x", LuaValue.valueOf(location.getBlockX()));
          table.set("y", LuaValue.valueOf(location.getBlockY()));
          table.set("z", LuaValue.valueOf(location.getBlockZ()));
          table.set("blockID", LuaValue.valueOf(block.getMaterial().getItemID()));
          table.set("blockData", LuaValue.valueOf((block).getData()));

          hook.execute(table);
        }
      }
    }
  }
コード例 #29
0
 public LuaValue method(String name, Object arg1, Object arg2) throws LuaError {
   return val.method(name, LuaValue.userdataOf(arg1), LuaValue.userdataOf(arg2));
 }
コード例 #30
0
 public LuaValue call(LuaValue arg) {
   String label = arg.checkjstring();
   int ret = j2meChoiceGroup.append(label, null);
   return valueOf(ret);
 }