LogFunction.cs 683 B

1234567891011121314151617181920212223242526
  1. namespace Lua.Standard.Mathematics;
  2. public sealed class LogFunction : LuaFunction
  3. {
  4. public static readonly LogFunction Instance = new();
  5. public override string Name => "log";
  6. protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
  7. {
  8. var arg0 = context.ReadArgument<double>(0);
  9. if (context.ArgumentCount == 1)
  10. {
  11. buffer.Span[0] = Math.Log(arg0);
  12. }
  13. else
  14. {
  15. var arg1 = context.ReadArgument<double>(1);
  16. buffer.Span[0] = Math.Log(arg0, arg1);
  17. }
  18. return new(1);
  19. }
  20. }