Reworked script function attribute, added initial math library

This commit is contained in:
2018-12-07 16:11:52 +01:00
parent 9bd82174f2
commit ac05647d71
15 changed files with 95 additions and 29 deletions

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Upsilon.BaseTypes;
using Upsilon.StandardLibraries;
using Type = Upsilon.BaseTypes.Type;
namespace Upsilon.BoundTypes
@@ -52,12 +54,25 @@ namespace Upsilon.BoundTypes
{
obj.Properties.Add(f.Name.ToLowerInvariant(), f);
}
var methods = backingType.GetMethods().Select(x => new UserDataBoundMethod()
var methods = new List<UserDataBoundMethod>();
var backingMethods = backingType.GetMethods();
foreach (var backingMethod in backingMethods)
{
Name = x.Name,
Type = Type.Function,
ResultType = x.ReturnType.GetScriptType()
});
if (backingMethod.IsSpecialName)
continue;
var name = backingMethod.Name;
var attribute = backingMethod.GetCustomAttribute(typeof(ScriptFunctionAttribute));
if (attribute is ScriptFunctionAttribute sfa )
{
name = sfa.Name;
}
methods.Add(new UserDataBoundMethod()
{
Name = name,
Type = Type.Function,
ResultType = backingMethod.ReturnType.GetScriptType()
});
}
foreach (var f in methods)
{
obj.Properties.Add(f.Name.ToLowerInvariant(), f);