|
|
@@ -1,4 +1,5 @@
|
|
|
using Lua.Standard.Base;
|
|
|
+using Lua.Standard.Mathematics;
|
|
|
|
|
|
namespace Lua.Standard;
|
|
|
|
|
|
@@ -15,6 +16,36 @@ public static class OpenLibExtensions
|
|
|
ToStringFunction.Instance
|
|
|
];
|
|
|
|
|
|
+ static readonly LuaFunction[] mathFunctions = [
|
|
|
+ AbsFunction.Instance,
|
|
|
+ AcosFunction.Instance,
|
|
|
+ AsinFunction.Instance,
|
|
|
+ Atan2Function.Instance,
|
|
|
+ AtanFunction.Instance,
|
|
|
+ CeilFunction.Instance,
|
|
|
+ CosFunction.Instance,
|
|
|
+ CoshFunction.Instance,
|
|
|
+ DegFunction.Instance,
|
|
|
+ ExpFunction.Instance,
|
|
|
+ FloorFunction.Instance,
|
|
|
+ FmodFunction.Instance,
|
|
|
+ FrexpFunction.Instance,
|
|
|
+ LdexpFunction.Instance,
|
|
|
+ LogFunction.Instance,
|
|
|
+ MaxFunction.Instance,
|
|
|
+ MinFunction.Instance,
|
|
|
+ ModfFunction.Instance,
|
|
|
+ PowFunction.Instance,
|
|
|
+ RadFunction.Instance,
|
|
|
+ RandomFunction.Instance,
|
|
|
+ RandomSeedFunction.Instance,
|
|
|
+ SinFunction.Instance,
|
|
|
+ SinhFunction.Instance,
|
|
|
+ SqrtFunction.Instance,
|
|
|
+ TanFunction.Instance,
|
|
|
+ TanhFunction.Instance,
|
|
|
+ ];
|
|
|
+
|
|
|
public static void OpenBaseLibrary(this LuaState state)
|
|
|
{
|
|
|
state.Environment["_G"] = state.Environment;
|
|
|
@@ -24,4 +55,19 @@ public static class OpenLibExtensions
|
|
|
state.Environment[func.Name] = func;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void OpenMathLibrary(this LuaState state)
|
|
|
+ {
|
|
|
+ state.Environment[RandomFunction.RandomInstanceKey] = new(new Random());
|
|
|
+ state.Environment["pi"] = Math.PI;
|
|
|
+ state.Environment["huge"] = double.PositiveInfinity;
|
|
|
+
|
|
|
+ var table = new LuaTable(0, mathFunctions.Length);
|
|
|
+ foreach (var func in mathFunctions)
|
|
|
+ {
|
|
|
+ table[func.Name] = func;
|
|
|
+ }
|
|
|
+
|
|
|
+ state.Environment["math"] = table;
|
|
|
+ }
|
|
|
}
|