|
@@ -13,9 +13,9 @@ namespace MoonSharp.Interpreter.CoreLib
|
|
|
[MoonSharpModule(Namespace = "math")]
|
|
[MoonSharpModule(Namespace = "math")]
|
|
|
public class MathModule
|
|
public class MathModule
|
|
|
{
|
|
{
|
|
|
- [MoonSharpConstant]
|
|
|
|
|
|
|
+ [MoonSharpModuleConstant]
|
|
|
public const double pi = Math.PI;
|
|
public const double pi = Math.PI;
|
|
|
- [MoonSharpConstant]
|
|
|
|
|
|
|
+ [MoonSharpModuleConstant]
|
|
|
public const double huge = double.MaxValue;
|
|
public const double huge = double.MaxValue;
|
|
|
|
|
|
|
|
private static Random GetRandom(Script s)
|
|
private static Random GetRandom(Script s)
|
|
@@ -80,79 +80,79 @@ namespace MoonSharp.Interpreter.CoreLib
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue abs(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue abs(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "abs", d => Math.Abs(d));
|
|
return exec1(args, "abs", d => Math.Abs(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue acos(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue acos(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "acos", d => Math.Acos(d));
|
|
return exec1(args, "acos", d => Math.Acos(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue asin(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue asin(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "asin", d => Math.Asin(d));
|
|
return exec1(args, "asin", d => Math.Asin(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue atan(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue atan(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "atan", d => Math.Atan(d));
|
|
return exec1(args, "atan", d => Math.Atan(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue atan2(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue atan2(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec2(args, "atan2", (d1, d2) => Math.Atan2(d1, d2));
|
|
return exec2(args, "atan2", (d1, d2) => Math.Atan2(d1, d2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue ceil(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue ceil(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "ceil", d => Math.Ceiling(d));
|
|
return exec1(args, "ceil", d => Math.Ceiling(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue cos(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue cos(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "cos", d => Math.Cos(d));
|
|
return exec1(args, "cos", d => Math.Cos(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue cosh(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue cosh(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "cosh", d => Math.Cosh(d));
|
|
return exec1(args, "cosh", d => Math.Cosh(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue deg(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue deg(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "deg", d => d * 180.0 / Math.PI);
|
|
return exec1(args, "deg", d => d * 180.0 / Math.PI);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue exp(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue exp(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "exp", d => Math.Exp(d));
|
|
return exec1(args, "exp", d => Math.Exp(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue floor(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue floor(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "floor", d => Math.Floor(d));
|
|
return exec1(args, "floor", d => Math.Floor(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue fmod(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue fmod(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec2(args, "fmod", (d1, d2) => Math.IEEERemainder(d1, d2));
|
|
return exec2(args, "fmod", (d1, d2) => Math.IEEERemainder(d1, d2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue frexp(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue frexp(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
// http://stackoverflow.com/questions/389993/extracting-mantissa-and-exponent-from-double-in-c-sharp
|
|
// http://stackoverflow.com/questions/389993/extracting-mantissa-and-exponent-from-double-in-c-sharp
|
|
@@ -211,31 +211,31 @@ namespace MoonSharp.Interpreter.CoreLib
|
|
|
return DynValue.NewTuple(DynValue.NewNumber(m), DynValue.NewNumber(e));
|
|
return DynValue.NewTuple(DynValue.NewNumber(m), DynValue.NewNumber(e));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue ldexp(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue ldexp(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec2(args, "ldexp", (d1, d2) => d1 * Math.Pow(2, d2));
|
|
return exec2(args, "ldexp", (d1, d2) => d1 * Math.Pow(2, d2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue log(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue log(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec2n(args, "log", Math.E, (d1, d2) => Math.Log(d1, d2));
|
|
return exec2n(args, "log", Math.E, (d1, d2) => Math.Log(d1, d2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue max(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue max(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return execaccum(args, "max", (d1, d2) => Math.Max(d1, d2));
|
|
return execaccum(args, "max", (d1, d2) => Math.Max(d1, d2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue min(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue min(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return execaccum(args, "min", (d1, d2) => Math.Min(d1, d2));
|
|
return execaccum(args, "min", (d1, d2) => Math.Min(d1, d2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue modf(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue modf(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
DynValue arg = args.AsType(0, "modf", DataType.Number, false);
|
|
DynValue arg = args.AsType(0, "modf", DataType.Number, false);
|
|
@@ -243,19 +243,19 @@ namespace MoonSharp.Interpreter.CoreLib
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue pow(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue pow(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec2(args, "pow", (d1, d2) => Math.Pow(d1, d2));
|
|
return exec2(args, "pow", (d1, d2) => Math.Pow(d1, d2));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue rad(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue rad(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "rad", d => d * Math.PI / 180.0);
|
|
return exec1(args, "rad", d => d * Math.PI / 180.0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue random(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue random(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
DynValue m = args.AsType(0, "random", DataType.Number, true);
|
|
DynValue m = args.AsType(0, "random", DataType.Number, true);
|
|
@@ -281,7 +281,7 @@ namespace MoonSharp.Interpreter.CoreLib
|
|
|
return DynValue.NewNumber(d);
|
|
return DynValue.NewNumber(d);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue randomseed(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue randomseed(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
DynValue arg = args.AsType(0, "randomseed", DataType.Number, false);
|
|
DynValue arg = args.AsType(0, "randomseed", DataType.Number, false);
|
|
@@ -290,31 +290,31 @@ namespace MoonSharp.Interpreter.CoreLib
|
|
|
return DynValue.Nil;
|
|
return DynValue.Nil;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue sin(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue sin(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "sin", d => Math.Sin(d));
|
|
return exec1(args, "sin", d => Math.Sin(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue sinh(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue sinh(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "sinh", d => Math.Sinh(d));
|
|
return exec1(args, "sinh", d => Math.Sinh(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue sqrt(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue sqrt(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "sqrt", d => Math.Sqrt(d));
|
|
return exec1(args, "sqrt", d => Math.Sqrt(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue tan(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue tan(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "tan", d => Math.Tan(d));
|
|
return exec1(args, "tan", d => Math.Tan(d));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [MoonSharpMethod]
|
|
|
|
|
|
|
+ [MoonSharpModuleMethod]
|
|
|
public static DynValue tanh(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
public static DynValue tanh(ScriptExecutionContext executionContext, CallbackArguments args)
|
|
|
{
|
|
{
|
|
|
return exec1(args, "tanh", d => Math.Tanh(d));
|
|
return exec1(args, "tanh", d => Math.Tanh(d));
|