Added LuaUserData.HasMember and made CreateStatic automatically add call metatable if it the type has a constructor

This commit is contained in:
EvilFactory
2024-08-08 19:30:41 -03:00
parent 496ce0fb91
commit 8d3d01c9e3
2 changed files with 47 additions and 2 deletions
@@ -284,6 +284,38 @@ namespace Barotrauma
descriptor.RemoveMember(memberName);
}
public static bool HasMember(object obj, string memberName)
{
if (obj == null) { throw new ScriptRuntimeException("object is nil"); }
Type type;
if (obj is Type)
{
type = (Type)obj;
}
else if(obj is IUserDataDescriptor descriptor)
{
type = descriptor.Type;
if (((StandardUserDataDescriptor)descriptor).HasMember(memberName))
{
return true;
}
}
else
{
type = obj.GetType();
}
if (type.GetMember(memberName).Length == 0)
{
return false;
}
return true;
}
/// <summary>
/// See <see cref="CreateUserDataFromType"/>.
/// </summary>