Fix incorrect LuaXXX type converter used in overload disambiguation

This commit is contained in:
peelz
2022-08-05 21:40:43 -04:00
parent 267644695a
commit 4f17a88781
2 changed files with 11 additions and 1 deletions
@@ -123,60 +123,70 @@ namespace Barotrauma
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(sbyte), clrDataType: typeof(sbyte),
canConvert: luaValue => luaValue.UserData?.Object is LuaSByte,
converter: luaValue => luaValue.UserData.Object is LuaSByte v converter: luaValue => luaValue.UserData.Object is LuaSByte v
? (sbyte)v ? (sbyte)v
: throw new ScriptRuntimeException("use SByte(value) to pass primitive type 'sbyte' to C#")); : throw new ScriptRuntimeException("use SByte(value) to pass primitive type 'sbyte' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(byte), clrDataType: typeof(byte),
canConvert: luaValue => luaValue.UserData?.Object is LuaByte,
converter: luaValue => luaValue.UserData.Object is LuaByte v converter: luaValue => luaValue.UserData.Object is LuaByte v
? (byte)v ? (byte)v
: throw new ScriptRuntimeException("use Byte(value) to pass primitive type 'byte' to C#")); : throw new ScriptRuntimeException("use Byte(value) to pass primitive type 'byte' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(short), clrDataType: typeof(short),
canConvert: luaValue => luaValue.UserData?.Object is LuaInt16,
converter: luaValue => luaValue.UserData.Object is LuaInt16 v converter: luaValue => luaValue.UserData.Object is LuaInt16 v
? (short)v ? (short)v
: throw new ScriptRuntimeException("use Int16(value) to pass primitive type 'short' to C#")); : throw new ScriptRuntimeException("use Int16(value) to pass primitive type 'short' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(ushort), clrDataType: typeof(ushort),
canConvert: luaValue => luaValue.UserData?.Object is LuaUInt16,
converter: luaValue => luaValue.UserData.Object is LuaUInt16 v converter: luaValue => luaValue.UserData.Object is LuaUInt16 v
? (ushort)v ? (ushort)v
: throw new ScriptRuntimeException("use UInt16(value) to pass primitive type 'ushort' to C#")); : throw new ScriptRuntimeException("use UInt16(value) to pass primitive type 'ushort' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(int), clrDataType: typeof(int),
canConvert: luaValue => luaValue.UserData?.Object is LuaInt32,
converter: luaValue => luaValue.UserData.Object is LuaInt32 v converter: luaValue => luaValue.UserData.Object is LuaInt32 v
? (int)v ? (int)v
: throw new ScriptRuntimeException("use Int32(value) to pass primitive type 'int' to C#")); : throw new ScriptRuntimeException("use Int32(value) to pass primitive type 'int' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(uint), clrDataType: typeof(uint),
canConvert: luaValue => luaValue.UserData?.Object is LuaUInt32,
converter: luaValue => luaValue.UserData.Object is LuaUInt32 v converter: luaValue => luaValue.UserData.Object is LuaUInt32 v
? (uint)v ? (uint)v
: throw new ScriptRuntimeException("use UInt32(value) to pass primitive type 'uint' to C#")); : throw new ScriptRuntimeException("use UInt32(value) to pass primitive type 'uint' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(long), clrDataType: typeof(long),
canConvert: luaValue => luaValue.UserData?.Object is LuaInt64,
converter: luaValue => luaValue.UserData.Object is LuaInt64 v converter: luaValue => luaValue.UserData.Object is LuaInt64 v
? (long)v ? (long)v
: throw new ScriptRuntimeException("use Int64(value) to pass primitive type 'long' to C#")); : throw new ScriptRuntimeException("use Int64(value) to pass primitive type 'long' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(ulong), clrDataType: typeof(ulong),
canConvert: luaValue => luaValue.UserData?.Object is LuaUInt64,
converter: luaValue => luaValue.UserData.Object is LuaUInt64 v converter: luaValue => luaValue.UserData.Object is LuaUInt64 v
? (ulong)v ? (ulong)v
: throw new ScriptRuntimeException("use UInt64(value) to pass primitive type 'ulong' to C#")); : throw new ScriptRuntimeException("use UInt64(value) to pass primitive type 'ulong' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(float), clrDataType: typeof(float),
canConvert: luaValue => luaValue.UserData?.Object is LuaSingle,
converter: luaValue => luaValue.UserData.Object is LuaSingle v converter: luaValue => luaValue.UserData.Object is LuaSingle v
? (float)v ? (float)v
: throw new ScriptRuntimeException("use Single(value) to pass primitive type 'float' to C#")); : throw new ScriptRuntimeException("use Single(value) to pass primitive type 'float' to C#"));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion( Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
scriptDataType: DataType.UserData, scriptDataType: DataType.UserData,
clrDataType: typeof(double), clrDataType: typeof(double),
canConvert: luaValue => luaValue.UserData?.Object is LuaDouble,
converter: luaValue => luaValue.UserData.Object is LuaDouble v converter: luaValue => luaValue.UserData.Object is LuaDouble v
? (double)v ? (double)v
: throw new ScriptRuntimeException("use Double(value) to pass primitive type 'double' to C#")); : throw new ScriptRuntimeException("use Double(value) to pass primitive type 'double' to C#"));