Merge pull request #104 from notpeelz/fix-hook-cs-compat
Fix Hook.Add compatibility with C# mods
This commit is contained in:
@@ -409,8 +409,13 @@ namespace Barotrauma
|
||||
() =>
|
||||
{
|
||||
if (getValidArgs == null) return null;
|
||||
return getValidArgs().ToObject<string[][]>();
|
||||
}, isCheat);
|
||||
var validArgs = getValidArgs();
|
||||
if (validArgs is DynValue luaValue)
|
||||
{
|
||||
return luaValue.ToObject<string[][]>();
|
||||
}
|
||||
return (string[][])validArgs;
|
||||
}, isCheat);
|
||||
|
||||
luaAddedCommand.Add(cmd);
|
||||
DebugConsole.Commands.Add(cmd);
|
||||
|
||||
@@ -6,16 +6,10 @@ using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public delegate DynValue CallLuaFunctionFunc(object function, params object[] args);
|
||||
|
||||
internal static class LuaCustomConverters
|
||||
partial class LuaCsSetup
|
||||
{
|
||||
private static CallLuaFunctionFunc CallLuaFunction;
|
||||
|
||||
public static void Initialize(CallLuaFunctionFunc callLuaFunction)
|
||||
private void RegisterLuaConverters()
|
||||
{
|
||||
CallLuaFunction = callLuaFunction;
|
||||
|
||||
RegisterAction<Item>();
|
||||
RegisterAction<Character>();
|
||||
RegisterAction<Entity>();
|
||||
@@ -194,7 +188,7 @@ namespace Barotrauma
|
||||
: throw new ScriptRuntimeException("use Double(value) to pass primitive type 'double' to C#"));
|
||||
}
|
||||
|
||||
public static void RegisterAction<T>()
|
||||
private void RegisterAction<T>()
|
||||
{
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Action<T>), v =>
|
||||
{
|
||||
@@ -209,7 +203,7 @@ namespace Barotrauma
|
||||
});
|
||||
}
|
||||
|
||||
public static void RegisterAction<T1, T2>()
|
||||
private void RegisterAction<T1, T2>()
|
||||
{
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Action<T1, T2>), v =>
|
||||
{
|
||||
@@ -224,7 +218,7 @@ namespace Barotrauma
|
||||
});
|
||||
}
|
||||
|
||||
public static void RegisterAction()
|
||||
private void RegisterAction()
|
||||
{
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Action), v =>
|
||||
{
|
||||
@@ -239,7 +233,7 @@ namespace Barotrauma
|
||||
});
|
||||
}
|
||||
|
||||
public static void RegisterFunc<T1>()
|
||||
private void RegisterFunc<T1>()
|
||||
{
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Func<T1>), v =>
|
||||
{
|
||||
@@ -254,7 +248,7 @@ namespace Barotrauma
|
||||
});
|
||||
}
|
||||
|
||||
public static void RegisterFunc<T1, T2>()
|
||||
private void RegisterFunc<T1, T2>()
|
||||
{
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Func<T1, T2>), v =>
|
||||
{
|
||||
@@ -269,7 +263,7 @@ namespace Barotrauma
|
||||
});
|
||||
}
|
||||
|
||||
public static void RegisterFunc<T1, T2, T3, T4, T5>()
|
||||
private void RegisterFunc<T1, T2, T3, T4, T5>()
|
||||
{
|
||||
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(Func<T1, T2, T3, T4, T5>), v =>
|
||||
{
|
||||
@@ -18,7 +18,7 @@ using Sigil.NonGeneric;
|
||||
namespace Barotrauma
|
||||
{
|
||||
public delegate void LuaCsAction(params object[] args);
|
||||
public delegate DynValue LuaCsFunc(params object[] args);
|
||||
public delegate object LuaCsFunc(params object[] args);
|
||||
public delegate DynValue LuaCsPatchFunc(object instance, LuaCsHook.ParameterTable ptable);
|
||||
|
||||
internal static class SigilExtensions
|
||||
@@ -777,9 +777,13 @@ namespace Barotrauma
|
||||
|
||||
var result = tuple.Item1.func(args);
|
||||
// TODO(BREAKING): change this to !result.IsVoid()
|
||||
if (result != null && !result.IsNil())
|
||||
if (result is DynValue luaResult && !luaResult.IsNil())
|
||||
{
|
||||
lastResult = result.ToObject<T>();
|
||||
lastResult = luaResult.ToObject<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
lastResult = (T)result;
|
||||
}
|
||||
|
||||
if (luaCs.PerformanceCounter.EnablePerformanceCounter)
|
||||
|
||||
@@ -409,7 +409,7 @@ namespace Barotrauma
|
||||
LuaScriptLoader = new LuaScriptLoader();
|
||||
LuaScriptLoader.ModulePaths = new string[] { };
|
||||
|
||||
LuaCustomConverters.Initialize(CallLuaFunction);
|
||||
RegisterLuaConverters();
|
||||
|
||||
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug);
|
||||
lua.Options.DebugPrint = PrintMessage;
|
||||
|
||||
Reference in New Issue
Block a user