Make userdata fields/properties/methods case insensitive
While this can potentially cause collisions, this allows us to easily use Lua's style guide
This commit is contained in:
parent
df8c7b99c9
commit
8f6d2591f3
|
@ -9,9 +9,9 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
public UserDataType(System.Type type)
|
public UserDataType(System.Type type)
|
||||||
{
|
{
|
||||||
Type = type;
|
Type = type;
|
||||||
Variables = type.GetFields().ToDictionary(x => x.Name, x => x);
|
Variables = type.GetFields().ToDictionary(x => x.Name.ToLowerInvariant(), x => x);
|
||||||
Properties = type.GetProperties().ToDictionary(x => x.Name, x => x);
|
Properties = type.GetProperties().ToDictionary(x => x.Name.ToLowerInvariant(), x => x);
|
||||||
Methods = type.GetMethods().ToDictionary(x => x.Name, x => x);
|
Methods = type.GetMethods().ToDictionary(x => x.Name.ToLowerInvariant(), x => x);
|
||||||
}
|
}
|
||||||
|
|
||||||
private System.Type Type { get; }
|
private System.Type Type { get; }
|
||||||
|
@ -23,6 +23,7 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
{
|
{
|
||||||
if (value.GetType() != Type)
|
if (value.GetType() != Type)
|
||||||
return null;
|
return null;
|
||||||
|
member = member.ToLowerInvariant();
|
||||||
if (Variables.TryGetValue(member, out var info))
|
if (Variables.TryGetValue(member, out var info))
|
||||||
{
|
{
|
||||||
return info.GetValue(value).ToLuaType();
|
return info.GetValue(value).ToLuaType();
|
||||||
|
@ -41,6 +42,7 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
|
|
||||||
public void Set(object value, string member, LuaType newValue)
|
public void Set(object value, string member, LuaType newValue)
|
||||||
{
|
{
|
||||||
|
member = member.ToLowerInvariant();
|
||||||
if (value.GetType() != Type)
|
if (value.GetType() != Type)
|
||||||
return;
|
return;
|
||||||
if (Variables.TryGetValue(member, out var info))
|
if (Variables.TryGetValue(member, out var info))
|
||||||
|
@ -51,7 +53,6 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
{
|
{
|
||||||
property.SetValue(value, newValue.ToCSharpObject());
|
property.SetValue(value, newValue.ToCSharpObject());
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -47,7 +47,7 @@ namespace UpsilonTests
|
||||||
var obj = new UserDataHelper();
|
var obj = new UserDataHelper();
|
||||||
const string input = @"
|
const string input = @"
|
||||||
function test(o)
|
function test(o)
|
||||||
return o[""FieldString""]
|
return o.fieldString
|
||||||
end
|
end
|
||||||
";
|
";
|
||||||
var script = new Script(input);
|
var script = new Script(input);
|
||||||
|
@ -63,7 +63,7 @@ end
|
||||||
var obj = new UserDataHelper();
|
var obj = new UserDataHelper();
|
||||||
const string input = @"
|
const string input = @"
|
||||||
function test(o)
|
function test(o)
|
||||||
o[""FieldStringSet""] = ""Test""
|
o.FieldStringSet = ""Test""
|
||||||
end
|
end
|
||||||
";
|
";
|
||||||
var script = new Script(input);
|
var script = new Script(input);
|
||||||
|
@ -79,7 +79,7 @@ end
|
||||||
var obj = new UserDataHelper();
|
var obj = new UserDataHelper();
|
||||||
const string input = @"
|
const string input = @"
|
||||||
function test(o)
|
function test(o)
|
||||||
o[""TestMethod""]()
|
o.testMethod()
|
||||||
end
|
end
|
||||||
";
|
";
|
||||||
var script = new Script(input);
|
var script = new Script(input);
|
||||||
|
@ -95,7 +95,7 @@ end
|
||||||
var obj = new UserDataHelper();
|
var obj = new UserDataHelper();
|
||||||
const string input = @"
|
const string input = @"
|
||||||
function test(o)
|
function test(o)
|
||||||
return o[""Add""](100, 20)
|
return o.add(100, 20)
|
||||||
end
|
end
|
||||||
";
|
";
|
||||||
var script = new Script(input);
|
var script = new Script(input);
|
||||||
|
|
Loading…
Reference in New Issue