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_InitIDbg( SGS_CTX, SGS_IDBG ) { D->C = C; sgs_GetMsgFunc( C, &D->pfn, &D->pctx ); sgs_SetMsgFunc( C, idbgPrintFunc, D ); D->input = sgs_membuf_create(); D->iword[0] = 0; D->inside = 0; D->minlev = SGS_WARNING; sgs_PushCFunction( C, idbg_stackitem ); sgs_StoreGlobal( C, "dbg_stackitem" ); sgs_PushCFunction( C, idbg_setstackitem ); sgs_StoreGlobal( C, "dbg_setstackitem" ); return SGS_SUCCESS; }
int ss_Initialize( int argc, char* argv[], int debug ) { int ret; SGS_CTX; GEnabledDebugging = debug; #if SS_STARTUP_PROFILING printf( "ss_Initialize called: %f\n", sgs_GetTime() ); #endif C = g_C = sgs_CreateEngine(); #if SS_STARTUP_PROFILING printf( "SGS engine created: %f\n", sgs_GetTime() ); #endif if( GEnabledDebugging ) sgs_InitIDbg( C, &D ); else sgs_SetMsgFunc( C, ss_MsgFunc, NULL ); #if SS_STARTUP_PROFILING printf( "debug printing initialized: %f\n", sgs_GetTime() ); #endif /* preinit first-use libs */ sgs_LoadLib_Fmt( C ); sgs_LoadLib_IO( C ); sgs_LoadLib_Math( C ); sgs_LoadLib_OS( C ); sgs_LoadLib_RE( C ); sgs_LoadLib_String( C ); #if SS_STARTUP_PROFILING printf( "SGS libraries loaded: %f\n", sgs_GetTime() ); #endif ss_InitDebug( C ); ss_InitExtMath( C ); ss_InitImage( C ); #if SS_STARTUP_PROFILING printf( "SS libraries loaded: %f\n", sgs_GetTime() ); #endif /* preinit tmp buffer */ g_tmpbuf = sgs_membuf_create(); sgs_membuf_reserve( &g_tmpbuf, C, 1024 ); /* load command line arguments */ { int i; for( i = 0; i < argc; ++i ) { sgs_PushString( C, argv[ i ] ); } sgs_CreateArray( C, NULL, argc ); sgs_SetGlobalByName( C, "sys_args", sgs_StackItem( C, -1 ) ); sgs_Pop( C, 1 ); } /* push some system info */ sgs_SetGlobalByName( C, "sys_scripting_engine", sgs_MakePtr( C ) ); #if SS_STARTUP_PROFILING printf( "system info pushed: %f\n", sgs_GetTime() ); #endif /* run the preconfig script */ sgs_ExecString( C, scr_preconfig ); #if SS_STARTUP_PROFILING printf( "preconfig done: %f\n", sgs_GetTime() ); #endif /* run the config file */ ret = sgs_Include( C, "core/config" ); if( !ret ) { sgs_Msg( C, SGS_ERROR, "Could not run core/config (configuration script)." ); return -2; } /* run the primary extensions */ ret = sgs_Include( C, "core/ext" ); if( !ret ) { sgs_Msg( C, SGS_ERROR, "Could not run core/ext." ); return -2; } #if SS_STARTUP_PROFILING printf( "configured engine scripts: %f\n", sgs_GetTime() ); #endif /* run the main file */ ret = sgs_Include( C, "main" ); if( !ret ) { sgs_Msg( C, SGS_ERROR, "Could not execute 'main'." ); return -3; } #if SS_STARTUP_PROFILING printf( "ran main script: %f\n", sgs_GetTime() ); #endif /* configure the framework (optional) */ sgs_GlobalCall( C, "configure", 0, 0 ); #if SS_STARTUP_PROFILING printf( "called 'configure': %f\n", sgs_GetTime() ); #endif /* check if already required to exit */ if( sgs_GlobalBool( C, "sys_exit" ) ) return 0; if( GEnabledProfiler ) sgs_ProfInit( C, &P, GEnabledProfiler ); #if SS_STARTUP_PROFILING printf( "pre-SDL init: %f\n", sgs_GetTime() ); #endif /* initialize SDL */ if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE ) < 0 ) { sgs_Msg( C, SGS_ERROR, "Couldn't initialize SDL: %s", SDL_GetError() ); return -5; } SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); #if SS_STARTUP_PROFILING printf( "post-SDL init: %f\n", sgs_GetTime() ); #endif /* initialize script-space SDL API */ ss_InitSDL( C ); /* initialize script-space rendering API */ ss_InitGraphics( C ); #if SS_STARTUP_PROFILING printf( "initialized SDL/Graphics subsystems: %f\n", sgs_GetTime() ); #endif /* initialize the application */ if( SGS_FAILED( sgs_GlobalCall( C, "initialize", 0, 0 ) ) ) { sgs_Msg( C, SGS_ERROR, "Failed to initialize the application." ); return -8; } #if SS_STARTUP_PROFILING printf( "called 'initialize': %f\n", sgs_GetTime() ); #endif return 1; }
static void initProfModeData1( sgs_ProfData* P, SGS_CTX ) { P->keytmp = sgs_membuf_create(); P->frametmp = sgs_membuf_create(); sgs_SetHookFunc( C, mode1hook, P ); }