PDA

View Full Version : Print any variable's content



serthy
13th September 2016, 18:46
I'm currently into debugging my code and I'd like to print any object to console.
However I cannot distinguish between an array, a struct or an int/float (if I use .size on an int, a compile error is emmitted):


PrintObject( obj )
{
elem = "undefined";

if( isDefined( array[ i ] ) )
{
if( isPlayer( obj ) )
elem = obj.name;
else if( isString( obj ) )
elem = sprintf( "\"%\"" , obj );
else // could be int/float or an array or a struct
elem = "{object}";
}

printf( "%\n" , elem );
}

Is there any way to get the type?

voron00
13th September 2016, 19:57
I beleive getType() is what you are looking for? https://github.com/voron00/libcod/blob/master/gsc.cpp#L89

kung foo man
13th September 2016, 23:28
Yup, returns every available gsc type possible



char *stackGetParamTypeAsString(int param) {
aStackElement *scriptStack = *(aStackElement**)getStack();
aStackElement *arg = scriptStack - param;

char *type = "UNKNOWN TYPE!";
switch (arg->type) {
case 0: type = "UNDEFINED"; break;
case 1: type = "OBJECT"; break;
case 2: type = "STRING"; break;
case 3: type = "LOCALIZED_STRING"; break;
case 4: type = "VECTOR"; break;
case 5: type = "FLOAT"; break;
case 6: type = "INT"; break;
case 7: type = "CODEPOS"; break;
case 8: type = "PRECODEPOS"; break;
case 9: type = "FUNCTION"; break;
case 10: type = "STACK"; break;
case 11: type = "ANIMATION"; break;
case 12: type = "DEVELOPER_CODEPOS"; break;
case 13: type = "INCLUDE_CODEPOS"; break;
case 14: type = "THREAD_LIST"; break;
case 15: type = "THREAD_1"; break;
case 16: type = "THREAD_2"; break;
case 17: type = "THREAD_3"; break;
case 18: type = "THREAD_4"; break;
case 19: type = "STRUCT"; break;
case 20: type = "REMOVED_ENTITY"; break;
case 21: type = "ENTITY"; break;
case 22: type = "ARRAY"; break;
case 23: type = "REMOVED_THREAD"; break;
}
return type;
}