Ejemplo n.º 1
0
void DumpModuleDlg::OnDumpBTN() 
{
	// TODO: Add your control notification handler code here
	TCHAR* extension = GenericPurposeMethods::GetExtension(shortmodulename);
	// Final string = "All Files (*.*)\0*.*\0\0";
	TCHAR* first_part = GenericPurposeMethods::JoinChars("PE Files (*",extension);
	first_part = GenericPurposeMethods::JoinChars(first_part,")");
	int fp_len = _tcslen(first_part);
	TCHAR* second_part = GenericPurposeMethods::JoinChars("*",extension);
	int sp_len = _tcslen(second_part);
	TCHAR* lpszFilter = new TCHAR[MAX_PATH];
	for (int i=0;i<fp_len;i++)
	lpszFilter[i]=first_part[i];  // copy first part

	lpszFilter[fp_len]=0;  // mark end of string

	for (int j=0;j<sp_len;j++)
	lpszFilter[fp_len+1+j]=second_part[j];  // copy first part

	lpszFilter[fp_len+sp_len+1]=0;  // mark end of string
	lpszFilter[fp_len+sp_len+2]=0;  // mark end of string

	CFileDialog dlg(FALSE, NULL, GenericPurposeMethods::GetDumpFileName(shortmodulename),
	OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, lpszFilter, this);
	// FALSE = save file dialog
	// CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL,
	// DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );

	dlg.m_ofn.lpstrInitialDir = GenericPurposeMethods::GetDirectory(fullmodulename);
    dlg.m_ofn.lpstrTitle="Save module!";

    if (dlg.DoModal() == IDOK)
    {
    CString filename = dlg.GetPathName(); // return full path and filename
	TCHAR* cfilename = new TCHAR[filename.GetLength()+1];
	lstrcpy(cfilename, filename);
	if (!GenericPurposeMethods::ContainsExtension(cfilename))
	{
	cfilename = GenericPurposeMethods::JoinChars(cfilename,extension);
	}
	DumpModule(cfilename);

    }
	

}
Ejemplo n.º 2
0
bool Test()
{
	bool fail = false;
	int r;
	COutStream out;

	const char *script = 
		"void Test() {} \n"
		"class A : I { void i(float) {} void a(int) {} float f; } \n"
		"class B : A { B(int) {} } \n"
		"interface I { void i(float); } \n"
		"float a; \n"
		"const float aConst = 3.141592f; \n"
		"I@ i; \n"
		"enum E { eval = 0, eval2 = 2 } \n"
		"E e; \n"
		"typedef float real; \n"
		"real pi = 3.14f; \n"
		"import void ImpFunc() from \"mod\"; \n";

	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);

	RegisterStdString(engine);

	float f;
	engine->RegisterTypedef("myFloat", "float");
	engine->RegisterGlobalProperty("myFloat f", &f);
	engine->RegisterGlobalProperty("const float myConst", &f);
	engine->RegisterGlobalFunction("void func(int &in)", asFUNCTION(0), asCALL_GENERIC);

	engine->BeginConfigGroup("test");
	engine->RegisterGlobalFunction("void func2()", asFUNCTION(0), asCALL_GENERIC);
	engine->EndConfigGroup();

	engine->RegisterEnum("myEnum");
	engine->RegisterEnumValue("myEnum", "value1", 1);
	engine->RegisterEnumValue("myEnum", "value2", 2);

	engine->RegisterFuncdef("void Callback(int a, int b)");

	engine->RegisterInterface("MyIntf");
	engine->RegisterInterfaceMethod("MyIntf", "void func() const");

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);

	mod->AddScriptSection("script", script);
	r = mod->Build();
	if( r < 0 )
		fail = true;

	WriteConfigToFile(engine, "AS_DEBUG/config.txt");

	DumpModule(mod);

	// Save/Restore the bytecode and then test again for the loaded bytecode
	CBytecodeStream stream(__FILE__"1");
	mod->SaveByteCode(&stream);

	mod = engine->GetModule("2", asGM_ALWAYS_CREATE);
	mod->LoadByteCode(&stream);

	DumpModule(mod);

	engine->Release();

	return fail;
}