void insert(ILuaTable table, ILuaValue pos, ILuaValue value = null) { CheckNotNull("table.insert", table); CheckNotNull("table.insert", pos); double i; double len = table.Length().AsDouble() ?? 0; if (value == null) { value = pos; i = len + 1; } else { i = pos.AsDouble() ?? 0; } if (i > len + 1 || i < 1 || i % 1 != 0) { throw new ArgumentException( "Position given to function 'table.insert' is outside valid range."); } for (double d = len; d >= i; d--) { var temp = table.GetItemRaw(E.Runtime.CreateValue(d)); table.SetItemRaw(E.Runtime.CreateValue(d + 1), temp); } table.SetItemRaw(pos, value); }
static IEnumerable <object> select(ILuaValue index, params object[] args) { if (index.Equals("#")) { return(new object[] { args.Length }); } else if (index.ValueType == LuaValueType.Number) { double ind = index.AsDouble() ?? 0; if (ind < 0) { ind = args.Length + ind + 1; } return(args.Skip((int)(ind - 1))); } else { throw new ArgumentException( "First argument to function 'select' must be a number or the string '#'."); } }
static double? tonumber(ILuaValue value) { return value.AsDouble(); }
static IEnumerable<object> select(ILuaValue index, params object[] args) { if (index.Equals("#")) { return new object[] { args.Length }; } else if (index.ValueType == LuaValueType.Number) { double ind = index.AsDouble() ?? 0; if (ind < 0) ind = args.Length + ind + 1; return args.Skip((int)(ind - 1)); } else { throw new ArgumentException( "First argument to function 'select' must be a number or the string '#'."); } }
static double?tonumber(ILuaValue value) { return(value.AsDouble()); }