Array.java 902 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package me.hammerle.snuviscript.compiler;
  2. import me.hammerle.snuviscript.code.InputProvider;
  3. import me.hammerle.snuviscript.code.Script;
  4. import me.hammerle.snuviscript.variable.Variable;
  5. public class Array extends Instruction
  6. {
  7. private final int arguments;
  8. private final ReturnWrapper wrapper = new ReturnWrapper();
  9. private final Variable v;
  10. public Array(int line, int arguments, Variable v)
  11. {
  12. super(line);
  13. this.arguments = arguments;
  14. this.v = v;
  15. }
  16. @Override
  17. public InputProvider execute(Script sc, InputProvider[] in) throws Exception
  18. {
  19. Object o = v.get(sc);
  20. for(InputProvider ip : in)
  21. {
  22. o = java.lang.reflect.Array.get(o, ip.getInt(sc));
  23. }
  24. wrapper.setValue(o);
  25. return wrapper;
  26. }
  27. @Override
  28. public int getArguments()
  29. {
  30. return arguments;
  31. }
  32. }