package net.engin33r.luaspigot.lua;

import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;

/**
 * Utility class for validating arguments against {@link WeakType} types.
 */
public class TypeValidator {
    public static void validate(LuaTable val, String type) {
        LuaValue ttype = val.get("type");
        if (ttype == LuaValue.NIL) {
            LuaValue.error(type + " expected, got table");
        } else {
            String vtype = ttype.tojstring();
            if (!vtype.equals(type))
                LuaValue.error(type + " expected, got " + vtype);
        }
    }
}

@@ -583,10 +583,813 @@
 %7D%0A    %7D%0A
+    public static void validateOf(LuaTable tbl, String type) %7B%0A        for (int i = 1; i %3C= tbl.length(); i++) %7B%0A            LuaTable val = tbl.get(i).checktable(i);%0A            LuaValue ttype = val.get(%22type%22);%0A            if (ttype == LuaValue.NIL) %7B%0A                LuaValue.error(%22table of %22 + type + %22 expected, got errant%22 +%0A                        %22 table%22);%0A            %7D else %7B%0A                String vtype = ttype.tojstring();%0A                if (!vtype.equals(type))%0A                    LuaValue.error(%22table of %22 + type + %22 expected, got%22 +%0A                            %22 errant %22 + vtype);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static boolean is(LuaValue val, String type) %7B%0A        return val.type() == LuaValue.TTABLE &&%0A                val.get(%22type%22).tojstring().equals(type);%0A    %7D%0A
 %7D%0A

Add more useful methods to TypeValidator