Reworked compatible external function parameters handling

This commit is contained in:
Deukhoofd 2018-12-09 14:14:43 +01:00
parent 2e0ac29878
commit 00cc59dfbd
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 30 additions and 8 deletions

View File

@ -140,26 +140,48 @@ namespace Upsilon.StandardLibraries
private static Type DeriveValidTypes(System.Type type) private static Type DeriveValidTypes(System.Type type)
{ {
var typeCode = System.Type.GetTypeCode(type);
switch (typeCode)
{
case TypeCode.Boolean:
return Type.Boolean;
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
return Type.Number;
case TypeCode.Char:
case TypeCode.String:
return Type.String;
case TypeCode.Object:
// allows every type
return (Type) 255;
}
if (type == typeof(ScriptString)) if (type == typeof(ScriptString))
return Type.String; return Type.String;
if (typeof(ScriptNumber).IsAssignableFrom(type)) if (typeof(ScriptNumber).IsAssignableFrom(type))
return Type.Number; return Type.Number;
if (type == typeof(ScriptBoolean)) if (type == typeof(ScriptBoolean))
return Type.Boolean; return Type.Boolean;
if (type == typeof(IIterable))
return Type.Table | Type.UserData;
if (typeof(ScriptTable).IsAssignableFrom(type)) if (typeof(ScriptTable).IsAssignableFrom(type))
return Type.Table; return Type.Table;
if (type == typeof(ScriptType)) if (type == typeof(ScriptType))
// allows every type // allows every type
return (Type) 255; return (Type) 255;
if (type == typeof(object))
// allows every type
return (Type) 255; if (type == typeof(IIterable))
return Type.Table | Type.UserData;
if (type.IsEnum) if (type.IsEnum)
return Type.Number; return Type.UserData | Type.Number;
if (type == typeof(string))
return Type.String;
if (typeof(IEnumerable).IsAssignableFrom(type)) if (typeof(IEnumerable).IsAssignableFrom(type))
return Type.Table | Type.UserData; return Type.Table | Type.UserData;
return Type.UserData; return Type.UserData;