Better error handling of getting userdata members
This commit is contained in:
parent
8dd2be8c67
commit
1d24be85d6
|
@ -27,10 +27,10 @@ namespace Upsilon.BaseTypes.UserData
|
|||
|
||||
public LuaType Get(Diagnostics diagnostics, TextSpan span, string s, EvaluationScope scope)
|
||||
{
|
||||
var (type, failed) = _typeInfo.Get(Value, s);
|
||||
var (type, failed, error) = _typeInfo.Get(Value, s);
|
||||
if (failed)
|
||||
{
|
||||
diagnostics.LogError($"Cannot find member '{s}' on type '{Value.GetType()}'", span);
|
||||
diagnostics.LogError(error, span);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -33,27 +33,28 @@ namespace Upsilon.BaseTypes.UserData
|
|||
private Dictionary<string, UserDataMethod> Methods { get; }
|
||||
private UserDataTypeOperators OperatorHandler { get; }
|
||||
|
||||
public (LuaType Type, bool Failed) Get(object value, string member)
|
||||
public (LuaType Type, bool Failed, string Error) Get(object value, string member)
|
||||
{
|
||||
if (value.GetType() != Type)
|
||||
return (null, true);
|
||||
return (null, true, "Invalid Type");
|
||||
member = member.ToLowerInvariant();
|
||||
if (Variables.TryGetValue(member, out var info))
|
||||
{
|
||||
return (info.GetValue(value).ToLuaType(), false);
|
||||
return (info.GetValue(value).ToLuaType(), false, null);
|
||||
}
|
||||
if (Properties.TryGetValue(member, out var property))
|
||||
{
|
||||
return (property.GetValue(value).ToLuaType(), false);
|
||||
return (property.GetValue(value).ToLuaType(), false, null);
|
||||
}
|
||||
if (Methods.TryGetValue(member, out var method))
|
||||
{
|
||||
return (new LuaMethodInfoFunction(method, value), false);
|
||||
return (new LuaMethodInfoFunction(method, value), false, null);
|
||||
}
|
||||
return (null, true);
|
||||
|
||||
return (null, true, $"Can't find public member '{member}' on type '{Type}'.");
|
||||
}
|
||||
|
||||
public (bool failed, string error) Set(object value, string member, LuaType newValue)
|
||||
public (bool Failed, string Error) Set(object value, string member, LuaType newValue)
|
||||
{
|
||||
member = member.ToLowerInvariant();
|
||||
if (value.GetType() != Type)
|
||||
|
|
Loading…
Reference in New Issue