Registered MathUtils and XMLExtensions as extension types, moved GetType to a better place
This commit is contained in:
@@ -22,6 +22,8 @@ sounds.HighShelfFilter = CreateStatic("Barotrauma.Sounds.HighShelfFilter")
|
||||
sounds.PeakFilter = CreateStatic("Barotrauma.Sounds.PeakFilter")
|
||||
defaultLib["Sounds"] = sounds
|
||||
|
||||
defaultLib["SpriteEffects"] = CreateStatic("Microsoft.Xna.Framework.Graphics.SpriteEffects")
|
||||
|
||||
defaultLib["SoundPlayer"] = CreateStatic("Barotrauma.SoundPlayer")
|
||||
defaultLib["SoundPrefab"] = CreateStatic("Barotrauma.SoundPrefab", true)
|
||||
defaultLib["BackgroundMusic"] = CreateStatic("Barotrauma.BackgroundMusic", true)
|
||||
|
||||
@@ -9,35 +9,7 @@ namespace Barotrauma
|
||||
{
|
||||
partial class LuaUserData
|
||||
{
|
||||
public static Type GetType(string typeName)
|
||||
{
|
||||
if (typeName == null || typeName.Length == 0) { return null; }
|
||||
|
||||
var byRef = false;
|
||||
if (typeName.StartsWith("out ") || typeName.StartsWith("ref "))
|
||||
{
|
||||
typeName = typeName.Remove(0, 4);
|
||||
byRef = true;
|
||||
}
|
||||
|
||||
var type = Type.GetType(typeName);
|
||||
if (type != null) { return byRef ? type.MakeByRefType() : type; }
|
||||
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (CsScriptBase.LoadedAssemblyName.Contains(a.GetName().Name))
|
||||
{
|
||||
var attrs = a.GetCustomAttributes<AssemblyMetadataAttribute>();
|
||||
var revision = attrs.FirstOrDefault(attr => attr.Key == "Revision")?.Value;
|
||||
if (revision != null && int.Parse(revision) != (int)CsScriptBase.Revision[a.GetName().Name]) { continue; }
|
||||
}
|
||||
type = a.GetType(typeName);
|
||||
if (type != null)
|
||||
{
|
||||
return byRef ? type.MakeByRefType() : type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static Type GetType(string typeName) => LuaCsSetup.GetType(typeName);
|
||||
|
||||
public static IUserDataDescriptor RegisterType(string typeName)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
||||
using System.Diagnostics;
|
||||
using MoonSharp.VsCodeDebugger;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.CsScriptAssembly, AllInternalsVisible = true)]
|
||||
namespace Barotrauma
|
||||
@@ -96,6 +97,36 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static Type GetType(string typeName, bool throwOnError = false, bool ignoreCase = false)
|
||||
{
|
||||
if (typeName == null || typeName.Length == 0) { return null; }
|
||||
|
||||
var byRef = false;
|
||||
if (typeName.StartsWith("out ") || typeName.StartsWith("ref "))
|
||||
{
|
||||
typeName = typeName.Remove(0, 4);
|
||||
byRef = true;
|
||||
}
|
||||
|
||||
var type = Type.GetType(typeName, throwOnError, ignoreCase);
|
||||
if (type != null) { return byRef ? type.MakeByRefType() : type; }
|
||||
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (CsScriptBase.LoadedAssemblyName.Contains(a.GetName().Name))
|
||||
{
|
||||
var attrs = a.GetCustomAttributes<AssemblyMetadataAttribute>();
|
||||
var revision = attrs.FirstOrDefault(attr => attr.Key == "Revision")?.Value;
|
||||
if (revision != null && int.Parse(revision) != (int)CsScriptBase.Revision[a.GetName().Name]) { continue; }
|
||||
}
|
||||
type = a.GetType(typeName, throwOnError, ignoreCase);
|
||||
if (type != null)
|
||||
{
|
||||
return byRef ? type.MakeByRefType() : type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ToggleDebugger(int port = 41912)
|
||||
{
|
||||
if (!GameMain.LuaCs.DebugServer.IsStarted)
|
||||
@@ -341,6 +372,9 @@ namespace Barotrauma
|
||||
UserData.RegisterType<LuaCsPerformanceCounter>();
|
||||
UserData.RegisterType<IUserDataDescriptor>();
|
||||
|
||||
UserData.RegisterExtensionType(typeof(MathUtils));
|
||||
UserData.RegisterExtensionType(typeof(XMLExtensions));
|
||||
|
||||
Lua.Globals["printerror"] = (DynValue o) => { LuaCsLogger.LogError(o.ToString(), LuaCsMessageOrigin.LuaMod); };
|
||||
|
||||
Lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
|
||||
|
||||
Reference in New Issue
Block a user