Sign in to follow this  
Rakkar2

Can't copy a string?

Recommended Posts

Sorry for this dumb question but after an hour I just can't figure it out. All I want to do is copy one string to another, using scriptstring that comes with AngelScript. I wrote a function that returns a string
ScriptManager::engine->RegisterObjectMethod(className, "const string& getName() const",  asMETHOD(Node, getName),asCALL_THISCALL);

And I want to copy it to another string. (Script)
string copiedString(this.getSceneNode().getName());
DebugPrint(1000, copiedString);

But I get an error:
No matching signatures to 'string(const string)'

(and)

Reference is read only

Ideas?

Share this post


Link to post
Share on other sites
This one is simple. :) I've just forgotten to register the copy constructor in the scriptstring.cpp file. If you add it, you shouldn't have any more problems copying the strings.

I'll make sure to add the registration of the copy constructor in a future version.

Regards,
Andreas

Share this post


Link to post
Share on other sites
Here it is:


static void ConstructString_Generic(asIScriptGeneric *gen)
{
asCScriptString *thisPointer = (asCScriptString *)gen->GetObject();
ConstructString(thisPointer);
}


static void ConstructStringCopy_Generic(const asCScriptString &str, asIScriptGeneric *gen)
{
asCScriptString *thisPointer = (asCScriptString *)gen->GetObject();
ConstructStringCopy(str, thisPointer);
}

r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f(const string &in)", asFUNCTION(ConstructStringCopy), asCALL_CDECL_OBJLAST); assert( r >= 0 );

r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f(const string &in)", asFUNCTION(ConstructStringCopy_Generic), asCALL_GENERIC); assert( r >= 0 );


Share this post


Link to post
Share on other sites
I'm having a similar problem.

string material = "MagnesiumBullet";
@billboardSet.setMaterialName(material);

Results in the following error:
Object handle is not supported for this type

The following registration was used:
result = ScriptManager::engine->RegisterObjectMethod("BillboardSet", "void setMaterialName(const string& inout)", asMETHODPR(BillboardSet, setMaterialName, (const string&), void),asCALL_THISCALL); RakAssert(result>=0)



I'll check the copy constructor again, but string should be a built in type.


This is the line of code where it errors: (as_compiler.cpp)
void asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asSExprContext *ctx)
{
int op = node->tokenType;

IsVariableInitialized(&ctx->type, node);

if( op == ttHandle )
{
// Verify that the type allow its handle to be taken
if( ctx->type.isExplicitHandle || !ctx->type.dataType.IsObject() || !ctx->type.dataType.GetObjectType()->beh.addref || !ctx->type.dataType.GetObjectType()->beh.release )
{
Error(TXT_OBJECT_HANDLE_NOT_SUPPORTED, node);



The objectType appears to be null...

[Edited by - tgraupmann on April 17, 2007 7:43:19 PM]

Share this post


Link to post
Share on other sites
Oddly Angelscript doesn't have any problem accessing the type. It just has problems associating a type with a method. If I pass the object and parameters to a function it works fine.

result = ScriptManager::engine->RegisterGlobalFunction("void setMaterialName(BillboardSet@, const string& in)", asFUNCTION(SetMaterialName), asCALL_CDECL); RakAssert(result>=0);

Share this post


Link to post
Share on other sites
Quote:
Original post by tgraupmann
I'm having a similar problem.

string material = "MagnesiumBullet";
@billboardSet.setMaterialName(material);

Results in the following error:
Object handle is not supported for this type

The following registration was used:
*** Source Snippet Removed ***

I'll check the copy constructor again, but string should be a built in type.


This is the line of code where it errors: (as_compiler.cpp)
*** Source Snippet Removed ***

The objectType appears to be null...


The expression "@billboardSet.setMaterialName(material);" is incorrect. With this you're actually trying to take the handle of the return type of the setMaterialName method, which in your case is void. That's why you're getting the error.

Anyway, I'm back from my vacation now, and I'll do my best to look into Rakkar2's problem as soon as possible.

Regards,
Andreas

Share this post


Link to post
Share on other sites
I just want to inform you that I've reproduced the problem and I'm working on the fix now.


// Test string copy constructor
int r = engine->ExecuteString(0, "string tst(getconststringref()); print(tst);");
if( r != asEXECUTION_FINISHED ) fail = true;
if( printOutput != "test" ) fail = true;



ExecuteString (1, 12) : Error : Reference is read-only


Regards,
Andreas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this