int ss_Free() { SGS_CTX = g_C; /* clean the application */ if( SGS_FAILED( sgs_GlobalCall( C, "cleanup", 0, 0 ) ) ) { sgs_Msg( C, SGS_ERROR, "Failed to clean the application." ); return -1; } sgs_membuf_destroy( &g_tmpbuf, C ); if( GEnabledProfiler ) { sgs_ProfDump( C, &P ); sgs_ProfClose( C, &P ); } if( GEnabledDebugging ) sgs_CloseIDbg( C, &D ); sgs_DestroyEngine( C ); ss_FreeGraphics( C ); return 0; }
static void idbgPrintFunc( void* data, SGS_CTX, int type, const char* message ) { SGS_IDBG = (sgs_IDbg*) data; D->stkoff = C->stack_off - C->stack_base; D->stksize = C->stack_top - C->stack_base; D->pfn( D->pctx, C, type, message ); if( D->inside || type < D->minlev ) return; D->inside = 1; C->sf_count -= SGS_IDBG_STACK_EXTENSION; printf( "----- Interactive SGScript Debug Inspector -----" ); for(;;) { printf( "\n> " ); idbg_readStdin( D ); if( ferror( stdin ) ) break; if( !*D->iword ) continue; if( STREQ( D->iword, "continue" ) || STREQ( D->iword, "cont" ) ) break; if( STREQ( D->iword, "quit" ) ) exit( 0 ); if( STREQ( D->iword, "reprint" ) ) D->pfn( D->pctx, C, type, message ); if( STREQ( D->iword, "stack" ) ) sgs_Stat( C, SGS_STAT_DUMP_STACK ); if( STREQ( D->iword, "globals" ) ) sgs_Stat( C, SGS_STAT_DUMP_GLOBALS ); if( STREQ( D->iword, "objects" ) ) sgs_Stat( C, SGS_STAT_DUMP_OBJECTS ); if( STREQ( D->iword, "callstack" ) || STREQ( D->iword, "frames" ) ) sgs_Stat( C, SGS_STAT_DUMP_FRAMES ); if( STREQ( D->iword, "exec" ) ) sgs_ExecBuffer( C, D->input.ptr + 5, D->input.size - 5 ); if( STREQ( D->iword, "eval" ) ) { int rvc = 0; sgs_EvalBuffer( C, D->input.ptr + 5, D->input.size - 5, &rvc ); sgs_PushGlobal( C, "printvars" ); sgs_Call( C, rvc, 0 ); } if( STREQ( D->iword, "print" ) ) { int rvc = 0; sgs_MemBuf prepstr = sgs_membuf_create(); sgs_membuf_appbuf( &prepstr, C, "return (", 8 ); sgs_membuf_appbuf( &prepstr, C, D->input.ptr + 5, D->input.size - 5 ); sgs_membuf_appbuf( &prepstr, C, ");", 2 ); sgs_EvalBuffer( C, prepstr.ptr, prepstr.size, &rvc ); sgs_membuf_destroy( &prepstr, C ); sgs_PushGlobal( C, "printvars" ); sgs_Call( C, rvc, 0 ); } } C->sf_count += SGS_IDBG_STACK_EXTENSION; D->inside = 0; }
int sgs_CloseIDbg( SGS_CTX, SGS_IDBG ) { sgs_SetMsgFunc( C, D->pfn, D->pctx ); sgs_membuf_destroy( &D->input, C ); return SGS_SUCCESS; }
static void freeProfModeData1( sgs_ProfData* P, SGS_CTX ) { sgs_membuf_destroy( &P->frametmp, C ); sgs_membuf_destroy( &P->keytmp, C ); }