Esempio n. 1
0
void InitFileFunctions()
{
    // create a class for file management
    // the use is as follows:
    // file canal( "NomFichier.txt" )
    // canal.open( "r" );   // open for read
    // s = canal.readln( ); // reads a line
    // canal.close();   // close the file

    // create the class FILE
    CBotClass* bc = CBotClass::Create("file", nullptr);
    // adds the component ".filename"
    bc->AddItem("filename", CBotTypString);
    // adds the component ".handle"
    bc->AddItem("handle", CBotTypInt, CBotVar::ProtectionLevel::Private);

    // define a constructor and a destructor
    bc->AddFunction("file", rfconstruct, cfconstruct);
    bc->AddFunction("~file", rfdestruct, nullptr);

    // end of the methods associated
    bc->AddFunction("open", rfopen, cfopen);
    bc->AddFunction("close", rfclose, cfclose);
    bc->AddFunction("writeln", rfwrite, cfwrite);
    bc->AddFunction("readln", rfread, cfread);
    bc->AddFunction("eof", rfeof, cfeof );

    CBotProgram::AddFunction("deletefile", rDeleteFile, cString);

    //m_pFuncFile = new CBotProgram( );
    //std::stringArray ListFonctions;
    //m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
    //m_pFuncFile->SetIdent(-2);  // restoreState in special identifier for this function
}
Esempio n. 2
0
BOOL CTestCBotApp::InitInstance()
{
//////////////////////////////////////////////
//	défini les mots clefs supplémentaires
// -------------------------------------------

	CBotProgram::Init();
 
//////////////////////////////////////////////
//	défini les fonctions "show()" et "print()"
// -------------------------------------------

	CBotProgram::AddFunction("show", rShow, cShow);
	CBotProgram::AddFunction("print", rPrint, cPrint);
	CBotProgram::AddFunction("println", rPrintLn, cPrint);


///////////////////////////////////
// définie la classe globale CPoint
// --------------------------------

	m_pClassPoint	= new CBotClass("CPoint", NULL);
	// ajoute le composant ".x"
	m_pClassPoint->AddItem("x", CBotTypFloat);
	// ajoute le composant ".y"
	m_pClassPoint->AddItem("y", CBotTypFloat);

	// ajoute le constructeur pour cette classe
	m_pClassPoint->AddFunction("CPoint", rCPoint, cCPoint);

	m_pClassPointIntr	= new CBotClass("point", NULL, TRUE);
	// ajoute le composant ".x"
	m_pClassPointIntr->AddItem("x", CBotTypFloat);
	// ajoute le composant ".y"
	m_pClassPointIntr->AddItem("y", CBotTypFloat);
	// ajoute le composant ".z"
	m_pClassPointIntr->AddItem("z", CBotTypFloat);

	// ajoute le constructeur pour cette classe
	m_pClassPointIntr->AddFunction("point", rCPoint, cCPoint);

	// défini la classe "object"
	CBotClass*	pClassObject = new CBotClass( "object", NULL ) ;
	pClassObject->AddItem( "xx", CBotTypFloat );
	pClassObject->AddItem( "position", CBotTypResult( CBotTypIntrinsic, "point" ) );
	pClassObject->AddItem( "transport", CBotTypResult( CBotTypPointer, "object" ) );
	pClassObject->AddUpdateFunc( rMajObject );

	InitClassFILE();
	
	AfxEnableControlContainer();

	// Standard initialization

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register document templates

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_TESTCBTYPE,
		RUNTIME_CLASS(CTestCBotDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CTestCBotView));
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if (m_lpCmdLine[0] == 0)
	{
		CString Filename = GetProfileString(szSection, szFilename);
		if (Filename.IsEmpty()) Filename = "TstCbot.txt";
		else OpenDocumentFile(Filename);
	}
	else
		// Dispatch commands specified on the command line
		if (!ProcessShellCommand(cmdInfo))
			return FALSE;
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();


	return TRUE;
}