MCPcopy Create free account
hub / github.com/anjo76/angelscript / ScriptObjectCopyFactory

Function ScriptObjectCopyFactory

sdk/angelscript/source/as_scriptobject.cpp:126–210  ·  view source on GitHub ↗

This helper function will call the copy factory, that is a script function TODO: Clean up: This function is almost identical to ScriptObjectFactory. Should make better use of the identical code.

Source from the content-addressed store, hash-verified

124// This helper function will call the copy factory, that is a script function
125// TODO: Clean up: This function is almost identical to ScriptObjectFactory. Should make better use of the identical code.
126asIScriptObject *ScriptObjectCopyFactory(const asCObjectType *objType, void *origObj, asCScriptEngine *engine)
127{
128 asIScriptContext *ctx = 0;
129 int r = 0;
130 bool isNested = false;
131
132 // Use nested call in the context if there is an active context
133 ctx = asGetActiveContext();
134 if (ctx)
135 {
136 // It may not always be possible to reuse the current context,
137 // in which case we'll have to create a new one any way.
138 if (ctx->GetEngine() == objType->GetEngine() && ctx->PushState() == asSUCCESS)
139 isNested = true;
140 else
141 ctx = 0;
142 }
143
144 if (ctx == 0)
145 {
146 // Request a context from the engine
147 ctx = engine->RequestContext();
148 if (ctx == 0)
149 {
150 // TODO: How to best report this failure?
151 return 0;
152 }
153 }
154
155 r = ctx->Prepare(engine->scriptFunctions[objType->beh.copyfactory]);
156 if (r < 0)
157 {
158 if (isNested)
159 ctx->PopState();
160 else
161 engine->ReturnContext(ctx);
162 return 0;
163 }
164
165 // Let the context handle the case for argument by ref (&) or by handle (@)
166 ctx->SetArgObject(0, origObj);
167
168 for (;;)
169 {
170 r = ctx->Execute();
171
172 // We can't allow this execution to be suspended
173 // so resume the execution immediately
174 if (r != asEXECUTION_SUSPENDED)
175 break;
176 }
177
178 if (r != asEXECUTION_FINISHED)
179 {
180 if (isNested)
181 {
182 ctx->PopState();
183

Callers 1

Calls 12

PushStateMethod · 0.80
RequestContextMethod · 0.80
PopStateMethod · 0.80
ReturnContextMethod · 0.80
SetArgObjectMethod · 0.80
ExecuteMethod · 0.80
SetExceptionMethod · 0.80
AbortMethod · 0.80
GetReturnAddressMethod · 0.80
GetEngineMethod · 0.45
PrepareMethod · 0.45
AddRefMethod · 0.45

Tested by

no test coverage detected