1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include "UnityPrefix.h"
#if ENABLE_SCRIPTING
#include "ScriptingInvocationNoArgs.h"
#include "Runtime/Utilities/LogAssert.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "ScriptingMethodRegistry.h"
#include "Runtime/Scripting/Backend/ScriptingBackendApi.h"
#include "Runtime/Profiler/Profiler.h"
#if ENABLE_MONO
#include "Runtime/Mono/MonoIncludes.h"
#include "Runtime/Mono/MonoManager.h"
#include "Runtime/Mono/MonoUtility.h"
#include "Runtime/Mono/MonoScript.h"
#endif
ScriptingInvocationNoArgs::ScriptingInvocationNoArgs()
{
SetDefaults();
}
ScriptingInvocationNoArgs::ScriptingInvocationNoArgs(ScriptingMethodPtr in_method)
{
SetDefaults();
method = in_method;
}
void ScriptingInvocationNoArgs::SetDefaults()
{
object = SCRIPTING_NULL;
method = SCRIPTING_NULL;
classContextForProfiler = NULL;
logException = true;
objectInstanceIDContextForException = 0;
exception = SCRIPTING_NULL;
}
bool ScriptingInvocationNoArgs::Check()
{
#if !ENABLE_MONO
return true;
#else
// Check method
if (method == NULL)
{
ErrorString("Failed to call function because it was null");
return false;
}
bool methodIsInstance = mono_signature_is_instance (mono_method_signature(method->monoMethod));
bool invokingInstance = object != NULL;
if (methodIsInstance && !invokingInstance)
{
DebugStringToFile (Format("Failed to call instance function %s because the no object was provided", mono_method_get_name (method->monoMethod)), 0, __FILE_STRIPPED__, __LINE__,
kError, objectInstanceIDContextForException);
return false;
}
if (!methodIsInstance && invokingInstance)
{
DebugStringToFile (Format("Failed to call static function %s because an object was provided", mono_method_get_name (method->monoMethod)), 0, __FILE_STRIPPED__, __LINE__,
kError, objectInstanceIDContextForException);
return false;
}
return true;
#endif
}
ScriptingObjectPtr ScriptingInvocationNoArgs::Invoke()
{
ScriptingExceptionPtr ex = NULL;
return Invoke(&ex);
}
ScriptingObjectPtr ScriptingInvocationNoArgs::Invoke(ScriptingExceptionPtr* exception)
{
ScriptingObjectPtr returnValue;
*exception = NULL;
#if ENABLE_MONO || UNITY_FLASH || UNITY_WINRT
ScriptingArguments arguments;
MONO_PROFILER_BEGIN (method, classContextForProfiler, object)
#if UNITY_WINRT
ScriptingObjectPtr metro_invoke_method(ScriptingMethodPtr method, ScriptingObjectPtr object, ScriptingArguments* arguments, ScriptingExceptionPtr* exception, bool convertArgs);
returnValue = metro_invoke_method(method, object, NULL, exception, false);
#else
returnValue = scripting_method_invoke(method, object, arguments, exception);
#endif
MONO_PROFILER_END
#elif !UNITY_EXTERNAL_TOOL
ErrorString("Invoke() not implemented on this platform");
#else
return NULL;
#endif
if (! *exception) return returnValue;
this->exception = *exception;
#if !UNITY_EXTERNAL_TOOL
if (logException)
Scripting::LogException(*exception, objectInstanceIDContextForException);
#endif
return SCRIPTING_NULL;
}
ScriptingObjectPtr ScriptingInvocationNoArgs::InvokeChecked()
{
if (!Check())
return SCRIPTING_NULL;
return Invoke();
}
#endif
|