コード例 #1
0
ファイル: IOBit.java プロジェクト: mhyst/w3s-lilisp
    public String evaluate(Program pgm, Variables vars, Instruction inst) throws Exception {
      Object[] objs = Bit.getObjects(pgm, vars, inst, 1);
      String type = objs[0].toString();
      String msg = "";
      for (int i = 1; i < objs.length; i++) {
        msg += objs[i].toString();
      }
      Type t = null;
      try {
        t = Type.valueOf(type);
      } catch (Exception e) {
        Bit.error(inst, "Invalid type, first parameter must be the type");
      }
      if (t == null) Bit.error(inst, "First parameter must be the type");

      String i;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.print(msg);
      i = br.readLine();
      while (!t.isValidValue(i)) {
        System.out.println("The value must be a valid " + t.name());
        System.out.print(msg);
        i = br.readLine();
      }

      Reference ref = new Reference();
      ref.type = t;
      ref.value = t.getObject(i, null);
      return pgm.getReferences().newReference(ref);
    }
コード例 #2
0
ファイル: IOBit.java プロジェクト: mhyst/w3s-lilisp
    public String evaluate(Program pgm, Variables vars, Instruction inst) throws Exception {
      Object[] objs = Bit.getObjects(pgm, vars, inst, 1);

      String title = objs[0].toString();
      String msg = objs[1].toString();
      String btnlabel = objs[2].toString();
      int width = Integer.parseInt(objs[3].toString());
      String type = objs[4].toString();
      Type t = Type.valueOf(type);
      if (t == null) Bit.error(inst, "Fifth parameter must be the type");
      RequestInput ri = pgm.getInput();
      Reference ref = ri.getInput(title, msg, width, btnlabel, t);
      ref.value = ref.value;
      return pgm.getReferences().newReference(ref);
    }