private double Random(Varargs args = null) { if (args == null || args.Count == 0) return rand.NextDouble(); else if (args.Count == 1) return rand.Next(1, 1 + Convert.ToInt32(args[0])); else if (args.Count >= 2) return rand.Next(Convert.ToInt32(args[0]), 1 + Convert.ToInt32(args[1])); return 0; }
private object MethodInteropCall(object target, Varargs parameters) { var table = target as LuaTable; var paramTypes = parameters.Select(x => x.GetType()).ToArray(); Varargs pair = table.Next(); do { var methodInfo = pair[0] as MethodInfo; if (methodInfo == null) continue; if (ParamsMatch(methodInfo, paramTypes) > 0) try { return methodInfo.Invoke(table.GetValue("__target"), parameters.ToArray()); } catch (Exception ex) { throw LuaRuntimeException.Create(Context, ex.Message, ex); } } while ((pair = table.Next(pair[0])) != null); throw LuaRuntimeException.Create(Context, "Could not find a method with the given parameters"); }