try to fix crashes under Mono when calling a cached function with the wrong arguments
This commit is contained in:
parent
fba66c3d28
commit
cef72bef4b
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using NLua.Native;
|
using NLua.Native;
|
||||||
|
|
||||||
namespace NLua.GenerateEventAssembly
|
namespace NLua.GenerateEventAssembly
|
||||||
|
|
|
@ -103,7 +103,7 @@ namespace NLua.Method
|
||||||
internal int SetPendingException(Exception e)
|
internal int SetPendingException(Exception e)
|
||||||
=> _translator.interpreter.SetPendingException(e);
|
=> _translator.interpreter.SetPendingException(e);
|
||||||
|
|
||||||
internal void FillMethodArguments(LuaState luaState, int numStackToSkip)
|
internal int FillMethodArguments(LuaState luaState, int numStackToSkip)
|
||||||
{
|
{
|
||||||
var args = _lastCalledMethod.args;
|
var args = _lastCalledMethod.args;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ namespace NLua.Method
|
||||||
if (_lastCalledMethod.argTypes[i].IsParamsArray)
|
if (_lastCalledMethod.argTypes[i].IsParamsArray)
|
||||||
{
|
{
|
||||||
var count = _lastCalledMethod.argTypes.Length - i;
|
var count = _lastCalledMethod.argTypes.Length - i;
|
||||||
var paramArray = _translator.TableToArray(luaState, type.ExtractValue, type.ParameterType, index, count);
|
var paramArray = ObjectTranslator.TableToArray(luaState, type.ExtractValue, type.ParameterType, index, count);
|
||||||
args[_lastCalledMethod.argTypes[i].Index] = paramArray;
|
args[_lastCalledMethod.argTypes[i].Index] = paramArray;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -125,9 +125,11 @@ namespace NLua.Method
|
||||||
if (_lastCalledMethod.args[_lastCalledMethod.argTypes[i].Index] == null &&
|
if (_lastCalledMethod.args[_lastCalledMethod.argTypes[i].Index] == null &&
|
||||||
!luaState.IsNil(i + 1 + numStackToSkip))
|
!luaState.IsNil(i + 1 + numStackToSkip))
|
||||||
{
|
{
|
||||||
throw new LuaException($"Argument number {(i + 1)} is invalid");
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal int PushReturnValue(LuaState luaState)
|
internal int PushReturnValue(LuaState luaState)
|
||||||
|
@ -224,7 +226,13 @@ namespace NLua.Method
|
||||||
throw new LuaException("Lua stack overflow");
|
throw new LuaException("Lua stack overflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
FillMethodArguments(luaState, numStackToSkip);
|
var invalidArgNum = FillMethodArguments(luaState, 0);
|
||||||
|
if (invalidArgNum != 0)
|
||||||
|
{
|
||||||
|
_translator.ThrowError(luaState, $"Argument number {invalidArgNum} is invalid");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return CallInvoke(luaState, method, targetObject);
|
return CallInvoke(luaState, method, targetObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +343,12 @@ namespace NLua.Method
|
||||||
throw new LuaException("Lua stack overflow");
|
throw new LuaException("Lua stack overflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
FillMethodArguments(luaState, 0);
|
var invalidArgNum = FillMethodArguments(luaState, 0);
|
||||||
|
if (invalidArgNum != 0)
|
||||||
|
{
|
||||||
|
_translator.ThrowError(luaState, $"Argument number {invalidArgNum} is invalid");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!_translator.MatchParameters(luaState, _method, _lastCalledMethod, 0))
|
else if (!_translator.MatchParameters(luaState, _method, _lastCalledMethod, 0))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1097,7 +1097,7 @@ namespace NLua
|
||||||
internal bool MatchParameters(LuaState luaState, MethodBase method, MethodCache methodCache, int skipParam)
|
internal bool MatchParameters(LuaState luaState, MethodBase method, MethodCache methodCache, int skipParam)
|
||||||
=> metaFunctions.MatchParameters(luaState, method, methodCache, skipParam);
|
=> metaFunctions.MatchParameters(luaState, method, methodCache, skipParam);
|
||||||
|
|
||||||
internal Array TableToArray(LuaState luaState, ExtractValue extractValue, Type paramArrayType, int startIndex, int count)
|
internal static Array TableToArray(LuaState luaState, ExtractValue extractValue, Type paramArrayType, int startIndex, int count)
|
||||||
=> MetaFunctions.TableToArray(luaState, extractValue, paramArrayType, ref startIndex, count);
|
=> MetaFunctions.TableToArray(luaState, extractValue, paramArrayType, ref startIndex, count);
|
||||||
|
|
||||||
private Type TypeOf(LuaState luaState, int idx)
|
private Type TypeOf(LuaState luaState, int idx)
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue