AngelScript 1.8.0 WIP #4 (2004/07/03)
You're too fast for me. Your method is actually working very well!
But the return value should be there anyway :)
Cheers
Tom
I'll probably make a similar macro for overloaded global functions as well, just for consistency. :)
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Quote: Original post by WitchLord
Actually, I don't think it is necessary to specify the return value as it is not used to identify overloaded functions. You can't overload a function just by changing the return value.
You're right overloading is defined in C++ only through the difference in parameters. But still I do get a compiler error when I specify the return value as void.
Using the macro
#define asMETHOD4(c,m,p) asSMethodPtr<sizeof(void (c::*)())>::Convert((void (c::*)p)(&c::m))
yields
d:\projects\AS\testframe\testtempvar.cpp(64) : error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'void (__thiscall Object1::* )(void)'
None of the functions with this name in scope match the target type
This might be a particularity of the VC7.1 compiler though.
I am using the macro
#define asMETHOD4(c,r,m,p) asSMethodPtr<sizeof(void (c::*)())>::Convert((r(c::*)p)(&c::m))
which works fine with vc7.1.
However, I really look forward to the new version.
Cheers
Tom
[edit]
WitchLord: I just saw that the link on the WIP page is still referencing WIP3 [/edit]
http://www.angelcode.com/angelscript/files/angelscript_sdk_180WIP4.zip
Thanks for letting me know.
It's strange, because the error message that you get is reporting the cast to a function with no parameters. Maybe that is the problem. Anyway, I'll include both of the macros, just in case.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
The changes should be mostly in registering in the methods. Maybe you could do a replace on '::' to ',' in those places? Doesn't work when registering overloaded functions, but the rest should work.
Other changes are the new parameter to set the module name, but you could just send NULL, or "", to get things working again.
If you need help you know how to contact me.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
I tried bstr.h/bstr.cpp with the testframework and it worked like a charm. Now, when I register my own String class the charm is gone ;(
I have tracked down the error to the factory method i'm using
but what I found there makes no sense for me:
length=199504708 ? it's a rather huge string, isn't it?
my factory looks like this:
String StringBinding::StringFactory(unsigned int length, const char *s){ if(length>0 && s!=NULL) { char* buf=new char[length]; memcpy(buf,s,length); String str(buf); delete [] buf; return str; } return String("");}
any idea why length is so big?
edit:
forgot to give the error message:
//Unhandled exception at 0x7c342eee (msvcr71.dll) in TechTest.exe: 0xC0000005: Access violation reading location 0x00000200.
If I'm right, angelscript is sending a hidden pointer as the first parameter, making your s to hold the length of the string. Try registering the string factory with asCALL_RETURNBYREF or asCALL_RETURNBYVAL.
This could be a bug in AngelScript. Could you give me the class declaration of the String object? I don't need the implementation. I would be able to make some tests that way.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
r=engine->RegisterObjectType("String",sizeof(String), asCALL_RETURNBYREF);r = engine->RegisterStringFactory("String", asFUNCTION4(StringBinding,String,StringFactory,(unsigned int length, const char *s)), asCALL_CDECL| asCALL_RETURNBYREF);
This is very strange though, because the factory doesn't return a reference to a String.
I must admit that I'm somewhat confuseld with the usage of the asCALL_RETURNBYREF / asCALL_RETURNBYVAL flags :)
You can download the String header file from here
http://thomas.webtracker.ch/jahia/album/thomas/as/ZolaString.h
Cheers
Tom
What was happening was that your string factory is taking a hidden pointer as the first parameter. Since AngelScript didn't know about this hidden pointer it didn't send one, making your function dislocate the parameters.
I admit that the asCALL_RETURN_BYREF and asCALL_RETURN_BYVAL flags are a bit confusing. I've already implemented another pair of flags for WIP5 that are easier to understand: asOBJ_IS_COMPLEX and asOBJ_IS_NOT_COMPLEX. Complex objects are those that have a defined constructor/destructor, or an overloaded assignment operator.
I know for sure that MSVC returns these kind of objects by reference even though you declare the method to return by value. What it does is make the caller allocate the memory for the object and passing a pointer to this memory in a hidden first parameter. The callee then calls the constructor using this memory pointer, and then returns the pointer.
I'm pretty sure that this behaviour is not the same for every compiler and platform so I decided to change these flags. With asOBJ_IS_COMPLEX and asOBJ_IS_NOT_COMPLEX it is easier for the programmer to identify the correct flag, and I will be able to put compiler/platform differences inside the library, making the code more portable.
WIP5 will probably be released on friday.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game