Jump to content
  • Advertisement
Sign in to follow this  
SomeFusion

Build fails

This topic is 4879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, can anybody see why this code won't work? This is my PrintTest class:
// header file
#pragma once

#include <iostream>
#include <string>

class PrintTest
{
public:
	PrintTest(void);
	~PrintTest(void);

	void ConstructPrintTest(PrintTest* pt);
	void DestructPrintTest(PrintTest* pt);
	void printText(void);
	void printText(std::string sometext);
};


// .cpp file

#include ".\printtest.h"

PrintTest::PrintTest(void)
{
	std::cout << "in printtest constructor" << std::endl;
}

PrintTest::~PrintTest(void)
{
	std::cout << "in printtest destructor" << std::endl;
}

void PrintTest::ConstructPrintTest(PrintTest* pt)
{
	new(pt) PrintTest();	
}

void PrintTest::DestructPrintTest(PrintTest* pt)
{
	pt->~PrintTest();
}

void PrintTest::printText(void)
{
	std::cout << "call of method without arguments" << std::endl;
}

void PrintTest::printText(std::string sometext)
{
	std::cout << sometext << std::endl;
}

And this is how I initialze AngelScript and register the void PrintTest::printText(void) method:
#include "angelscript.h"
#include "PrintTest.h"

#include <assert.h>
#include <string>
#include <fstream>

std::string LoadScript(const std::string &scriptfile);

class COutputStream : public asIOutputStream
{
public:
	void Write(const char *text) { std::cout << text; }
};

int main()
{
	int r = 0;
	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	if(engine == 0)
		std::cout << "could not create the script engine" << std::endl;


	
	r = engine->RegisterObjectType("PrintTest", sizeof(PrintTest), asOBJ_CLASS_CD);
	assert(r >= 0);
	r = engine->RegisterObjectBehaviour("PrintTest", asBEHAVE_CONSTRUCT, "void f()",asMETHOD(PrintTest, ConstructPrintTest), asCALL_THISCALL);
	assert(r >= 0);
	r = engine->RegisterObjectBehaviour("PrintTest", asBEHAVE_DESTRUCT, "void f()",asMETHOD(PrintTest, DestructPrintTest), asCALL_THISCALL);
	assert(r >= 0);

	//r = engine->RegisterObjectMethod("PrintTest", "void printText()", asMETHODPR(PrintTest, printText,(void), void ), asCALL_THISCALL);
	r = engine->RegisterObjectMethod("PrintTest", "void printText(void)", asMETHOD(PrintTest, printText), asCALL_THISCALL);
	assert(r >= 0);													  

	std::string script = LoadScript("testscript.txt");
	r = engine->AddScriptSection("module", "test", script.c_str(), script.length());
	assert(r >= 0);

	COutputStream out;
	r = engine->Build("module", &out);
	assert(r >= 0);

	int funcID = engine->GetFunctionIDByDecl("module", "void test()");
	
	
	asIScriptContext* testContext = 0;
	engine->CreateContext(&testContext);

	return 0;
}


std::string LoadScript(const std::string &scriptfile)
{
	std::ifstream fin(scriptfile.c_str());
	char ch;
	std::string script_contents;

	while(fin.get(ch))
	{
		script_contents += ch;
	}

	fin.close();
	return script_contents;
}

This is my script file:
void test()
{
	PrintTest pt;
	pt.printText(void);
}
The assertion at engine->Build() fails. The out stream says: test (4, 15) : Error : Expected identifier Whats wrong with my script? when I comment out pt.printText(void); then suddenly everything works. Keep up the great wik with AS! thanks, SomeFusion

Share this post


Link to post
Share on other sites
Advertisement
Remove that 'void' argument, and see if it works. That's c-syntax and is not required by C++ or AS.

Share this post


Link to post
Share on other sites
Wohoo! it works now after some other problems :). One of wich were the same ESP problem like descriped in that topic (http://www.gamedev.net/community/forums/topic.asp?topic_id=315578).
This should be corrected in the manual, in the section "Overview of AngelScript" in "Constructors and destructors" since it may cause problems to other people too. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!