function call does not return...

Started by
3 comments, last by Risto Hietanen 18 years, 4 months ago
Hi! I have a problem I can't figure out. This is the situation: I have a singleton class in my application that have to functions: void test1() { TRACE_0("Hello from test1()\n"); } void test2(asCScriptString *s) { string input; input = string(s->buffer); TRACE_1("Hello from test2() : %s\n", input); } Both functions are registered according to: asRet= m_scriptEngine->RegisterGlobalFunction("void test1()", asMETHOD(CSTester, test1), asCALL_CDECL); assert( asRet >= 0 ); asRet= m_scriptEngine->RegisterGlobalFunction("void test2(string @s)", asMETHOD(CSTester, test2), asCALL_CDECL); assert( asRet >= 0 ); The script looks like: void Setup() { Print("*** SCRIPT 1 STARTED ***\n"); string a = "hello"; test1(); test2(a,a,a); Print("*** SCRIPT 1 COMPLETED ***\n"); } And the problem is: Everything hangs when the function test2() returns. If i only call the test1() function everything works fine. But if I call test2() everything hangs and the last line in the script ( Print("*** SCRIPT 1 COMPLETED ***\n"); ) is not executed. Furthermore, in the application both test1() and test2() executes their TRACE statements, i.e. prints "Hello from test1()" and "Hello from test2() : hello" respectively. Any ideas as to what I am doing wrong? Best Regadrs, Risto
Advertisement
It looks like you're registering class methods as global functions. That would surely cause problems when AngelScript is calling the methods thinking they are global functions.

Or perhaps they are static methods on the CSTester class?

If they are not static methods, then you'll need to write global wrapper functions that can call the singleton's methods. Or, you could register the singleton class and let the scripts call the methods on it.

Also, this is probably a typo, but you registered test2 to take one parameter, yet in the script you're passing it three strings.

You may also want to release the script string in the test2() method before it returns, otherwise the string passed in from the string will leak. If you can't release the string, you'll have to change the way you registered the function. Either use a reference (const string &in), or an autohandle (string @+).

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hi!

Thanks for Your quick answer. I should have given you this information as well:
The CSTester class is derived from a scingleton template class according to:
class CSTester : public CSingleton<CSTester >

And yes, the 3 inparamters were a typo :)


I did try to register the functions Test1 and Test2 as class methods for the class CSTester according to:

asRet = m_scriptEngine->RegisterObjectType("Tester", 0, asOBJ_CLASS); assert( asRet >= 0 );

asRet= m_scriptEngine->RegisterObjectMethod("Tester","void test1()", asMETHOD(CSTester, Test1), asCALL_THISCALL); assert( asRet >= 0 );

asRet= m_scriptEngine->RegisterObjectMethod("Tester","void test2(string @s)", asMETHOD(CSTester, test2), asCALL_THISCALL); assert( asRet >= 0 );

but then I get the following error:
# script1.as (1,1) : Info Compiling void Setup()
# script1.as (8,10) : Error : No matching signature to 'test1()'
# script1.as (10,1) : Error : No matching signature to 'test2(string&)'

Do I also need to register the singleton: template<typename T> class CSingleton? And in that case how do go about to do that?

Best Regards,
Risto



I believe WL gave you the answer to your problem already.

register your methods using the auto handle @+

Or, change the signature of your method to:

(const string &in)
Hi!

I figured out (with your help :) how to get everything to work. I simply registered the singelton CSTester object as an global variable. The script can then access the object and its registered methods. Everything works perfectly!

Best Regards,
Risto

This topic is closed to new replies.

Advertisement