// substr arr start end public static Option substr(List<Option> args) { OptionArray arr = (OptionArray)args[0]; int start = ((OptionInt)args[1]).Value; int end = ((OptionInt)args[2]).Value; OptionArray ret = new OptionArray("", "array " + arr.TypeName.Split()[1] + " " + (end - start)); for (int i = start; i < end; i++) ret.setOption(i - start, arr.getOption(i)); return ret; }
public static Option pack_bool(List<Option> args) { OptionArray arr = (OptionArray)args[0]; List<Byte> data = new List<Byte>(); byte b = 0; for (int i = 0; i < arr.Count; i++) { if (((OptionBool)arr.getOption(i)).Value) b |= (byte)(1 << (i % 8)); if (i != 0 && i % 8 == 0) // Full byte done, next please { data.Add(b); b = 0; } } OptionArray ret = new OptionArray("", "array bool " + data.Count); for(int i = 0; i < data.Count; i ++) ret.setOption(i, new OptionInt("", data[i], 0, 255, 1)); return ret; }