コード例 #1
0
ファイル: dao_webdemo.c プロジェクト: dreamsxin/dao-tools
void DaoWebDemo_AddModules( DaoVmSpace *vmspace )
{
	DaoVmSpace_AddVirtualModules( vmspace, dao_virtual_modules );
}
コード例 #2
0
ファイル: daoMain.c プロジェクト: daokoder/dao
int main( int argc, char **argv )
{
	int restart = 0;
	int i, k, idsrc, vmods = 0;
	DString *opts = NULL, *args = NULL;

	/*mtrace(); */

	for(i=1; i<argc; i++){
		if( strcmp( argv[i], "-r" ) ==0 || strcmp( argv[i], "--restart" ) ==0 ){
			restart = i;
			break;
		}
	}
	if( restart ) DaoRestartRun( argv, argc, restart );

	vmSpace = DaoInit( argv[0] );

	idsrc = -1;
	for(i=1; i<argc; i++){
		if( strcmp( argv[i], "-e" ) ==0 || strcmp( argv[i], "--eval" ) ==0 ) break;
		/* also allows execution of script files without suffix .dao */
		if( argv[i][0] != '-' ){
			idsrc = i;
			break;
		}
	}

#ifdef DAO_WITH_STATIC_MODULES
	/*
	// For single file deployment.
	// Identify the script argument, such that the arguments before the script
	// can be passed in as virtual machine arguments.
	// Example: ./script --restart script.dao ...
	*/
	args = DString_Copy( vmSpace->daoBinFile );
	DString_Erase( args, 0, vmSpace->daoBinPath->size );
	DString_AppendChars( args, ".dao" );
	idsrc = 1;
	for(i=1; i<argc; i++){
		if( strcmp( argv[i], args->chars ) == 0 ){
			idsrc = i;
			break;
		}
	}
	vmods = DaoVmSpace_AddVirtualModules( vmSpace, dao_virtual_modules );
	DString_Reset( args, 0 );
#endif

	k = idsrc;
	if( k < 0 ) k = argc;

	if( opts == NULL ) opts = DString_New();
	if( args == NULL ) args = DString_New();
	for(i=1; i<k; i++ ){
		DString_AppendChars( opts, argv[i] );
		DString_AppendChar( opts, '\1' );
	}
	if( idsrc >= 0 ){
#ifdef DAO_WITH_STATIC_MODULES
		idsrc += 1;
#endif
		for(i=idsrc; i<argc; i++ ){
			DString_AppendChars( args, argv[i] );
			DString_AppendChar( args, '\1' );
		}
	}
	DaoVmSpace_ParseOptions( vmSpace, DString_GetData( opts ) );

#ifdef DAO_WITH_STATIC_MODULES
	if( vmods ){
		DString_InsertChars( args, "/@/\1", 0, 0, 0 );
		DString_InsertChars( args, dao_virtual_modules[0].name, 3, 0, 0 );
		/* set the path for the virtual files: */
		DaoVmSpace_SetPath( vmSpace, "/@/" );
	}else
#endif
	if( idsrc < 0 && argc == 1 ){
		DString_AppendChar( opts, '\1' );
		DString_AppendChars( opts, "-vi" );
		DaoVmSpace_ParseOptions( vmSpace, DString_GetData( opts ) );
	}


#ifdef DAO_USE_READLINE
	DaoVmSpace_ReadLine( vmSpace, DaoReadLine );
	DaoVmSpace_AddHistory( vmSpace, (AddHistory) add_history );
	read_history( NULL );
#endif

	signal( SIGINT, DaoSignalHandler );
	signal( SIGSEGV, DaoStackTrace );

	/* Start execution. */
	k = DaoVmSpace_RunMain( vmSpace, DString_GetData( args ) );

#ifdef DAO_USE_READLINE
	write_history( NULL );
#endif

	DString_Delete( args );
	DString_Delete( opts );
	DaoQuit();
	return k;
}