Browse Source

Add: type

AnnulusGames 1 year ago
parent
commit
9c63df2f3e
1 changed files with 27 additions and 0 deletions
  1. 27 0
      src/Lua/Standard/Basic/TypeFunction.cs

+ 27 - 0
src/Lua/Standard/Basic/TypeFunction.cs

@@ -0,0 +1,27 @@
+namespace Lua.Standard.Basic;
+
+public sealed class TypeFunction : LuaFunction
+{
+    public override string Name => "type";
+    public static readonly TypeFunction Instance = new();
+
+    protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
+    {
+        var arg0 = context.ReadArgument(0);
+        
+        buffer.Span[0] = arg0.Type switch
+        {
+            LuaValueType.Nil => "nil",
+            LuaValueType.Boolean => "boolean",
+            LuaValueType.String => "string",
+            LuaValueType.Number => "number",
+            LuaValueType.Function => "function",
+            LuaValueType.Thread => "thread",
+            LuaValueType.UserData => "userdata",
+            LuaValueType.Table => "table",
+            _ => throw new NotImplementedException(),
+        };
+
+        return new(1);
+    }
+}