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

Function PrintVariables

sdk/tests/test_feature/source/test_debug.cpp:190–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188
189bool doSkipTemporary = true;
190void PrintVariables(asIScriptContext *ctx, asUINT stackLevel)
191{
192 asIScriptEngine *engine = ctx->GetEngine();
193
194 int typeId = ctx->GetThisTypeId(stackLevel);
195 void *varPointer = ctx->GetThisPointer(stackLevel);
196 if( typeId )
197 {
198 print(" this = 0x%x\n", varPointer);
199 }
200
201 int numVars = ctx->GetVarCount(stackLevel);
202 for( int n = 0; n < numVars; n++ )
203 {
204 // Skip temporary variables
205 const char* name;
206 ctx->GetVar(n, stackLevel, &name, &typeId);
207 if ((name == 0 || strlen(name) == 0) && doSkipTemporary)
208 continue;
209
210 bool inScope = false;
211 if (ctx->IsVarInScope(n, stackLevel))
212 {
213 print(" (in scope)");
214 inScope = true;
215 }
216 else
217 print(" (no scope)");
218
219 varPointer = ctx->GetAddressOfVar(n, stackLevel);
220 if( typeId == engine->GetTypeIdByDecl("int") )
221 {
222 if (inScope)
223 print(" %s%s = %d\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "", *(int*)varPointer);
224 else
225 print(" %s%s = {uninitialized}\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "");
226 }
227 else if (typeId == engine->GetTypeIdByDecl("uint"))
228 {
229 if (inScope)
230 print(" %s%s = %u\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "", *(asUINT*)varPointer);
231 else
232 print(" %s%s = {uninitialized}\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "");
233 }
234 else if( typeId == engine->GetTypeIdByDecl("string") )
235 {
236 CScriptString *str = (CScriptString*)varPointer;
237 if( str )
238 print(" %s%s = '%s'\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "", str->buffer.c_str());
239 else
240 print(" %s%s = <null>\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "");
241 }
242 else if (typeId == engine->GetTypeIdByDecl("foo"))
243 {
244 if (varPointer)
245 print(" %s%s = %d\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "", *(int*)varPointer);
246 else
247 print(" %s%s = <null>\n", ctx->GetVarDeclaration(n, stackLevel), (name == 0 || strlen(name) == 0) ? "(temp)" : "");

Callers 4

LineCallback2Function · 0.85
LineCallback3Function · 0.85
LineCallback4Function · 0.85
ExceptionCallbackFunction · 0.85

Calls 10

GetThisTypeIdMethod · 0.80
GetThisPointerMethod · 0.80
IsVarInScopeMethod · 0.80
GetAddressOfVarMethod · 0.80
GetVarDeclarationMethod · 0.80
printFunction · 0.70
GetEngineMethod · 0.45
GetVarCountMethod · 0.45
GetVarMethod · 0.45
GetTypeIdByDeclMethod · 0.45

Tested by

no test coverage detected