🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

AngelScript 2.5.0c released

Started by
44 comments, last by WitchLord 18 years, 4 months ago
I'm actually registering smart pointers, and leading AngelScript to believe they are the full fledged object. In angelscript, it's just Object a; a.somemethod(); When, in fact, 'Object' happens to really be a smart pointer and doesn't have that method at all! It's amazing what kind of tricks you can pull with the binding mechanism.

Incidentally, Witchlord, will we be seeing an overloadable operator++ anytime? I'm binding iterator interfaces, and am stuck using a member function on the iterator type instead. I understand that unary operator* left with pointers; will it come back with them?
Advertisement
overloads for the ++ operators will be available, however for me they are low-priority. Should anyone want to implement them and pass the implementation to me I'd be more than happy to accept that contribution.

All the pointer operators will come back with the pointers. Including the address-of, &, operator that wasn't even available before.

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: overloads for the ++ operators will be available, however for me they are low-priority. Should anyone want to implement them and pass the implementation to me I'd be more than happy to accept that contribution.


I'm going to go look at that. :)

Quote:
All the pointer operators will come back with the pointers. Including the address-of, &, operator that wasn't even available before.

Does that include an operator[] that is already defined for pointer types?
Yes, that is the plan. The new pointers will have the same freedom as in C++, with all the dangers that comes with it. [wink]

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

so before pointer is put back, i may need to use smart pointer.

but how to use it ? any hints ?
You can register it as a type, then write wrappers for all the methods of the pointee-type that take a pointer to the smartpointer as the this pointer. The scripts will just see an object with it's methods, while in actuallity it is a smartpointer, and the method calls indirect through the pointer, and are possibly even virtual.

Ripped right from my current project.
namespace{	std::string wrap_parm(std::string name, Database::ObjectPointer* thisp)	{		if (!*thisp) return "";		return (*thisp)->get_parameter(name).value;	}	void wrap_send(const std::string& msg, Database::ObjectPointer* thisp)	{		if (!*thisp)  return;		(*thisp)->send(msg);	}	Database::ObjectPointer& wrap_loc(Database::ObjectPointer* thisp)	{		return (*thisp)->location;	}		Database::ObjectSet& get_contents(Database::ObjectPointer* thisp)	{		return (*thisp)->contents;	}	bool good(Database::ObjectPointer* thisp)	{		return (*thisp);	}};REGISTER_COMPLETE_BASIC_TYPE("Object",Database::ObjectPointer);REGISTER_METHOD("Object","string get_parameter(string)",asFUNCTION(wrap_parm),asCALL_CDECL_OBJLAST);REGISTER_METHOD("Object","void send(const string&)",asFUNCTION(wrap_send),asCALL_CDECL_OBJLAST);REGISTER_METHOD("Object","Object& location()",asFUNCTION(wrap_loc),asCALL_CDECL_OBJLAST);REGISTER_METHOD("Object","ObjectSet& contents()",asFUNCTION(get_contents),asCALL_CDECL_OBJLAST);REGISTER_METHOD("Object","bool good()",asFUNCTION(good),asCALL_CDECL_OBJLAST);REGISTER_BEHAVIOR(asBEHAVE_EQUAL,"bool op_equal(const Object&,const Object&)",asFUNCTION((Wrap::Equal<Database::ObjectPointer,Database::ObjectPointer>)),asCALL_CDECL);REGISTER_BEHAVIOR(asBEHAVE_NOTEQUAL,"bool op_notequal(const Object&,const Object&)",asFUNCTION((Wrap::NotEqual<Database::ObjectPointer,Database::ObjectPointer>)),asCALL_CDECL);


In this example, Database::ObjectPointer is a typedef for boost::intrusive_ptr<Database::Object>.
what is REGISTER_COMPLETE_BASIC_TYPE?

Deyja:

Thanks for helping out. I didn't have a readily available example to show.

Rain Dog:

If I'm not mistaken REGISTER_COMPLETE_BASIC_TYPE would be a macro defined by Deyja that registers an object type and most likely the basic behaviours, such as the constructor, addref, release, and assignment operators.

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

It doesn't really matter what it is. It just registers the default constructor, copy contrustor, destructor, and operator=.

Unfortunatly, this technigue makes it impossible to directly register member data, hence the 'contents()' member function.
I've released yet more bug fixes for AngelScript. Some of these fixes will also be applied to the 2.4.1 version as soon as I get the time to do so.

Thanks goes to villemon and topcatse from the GameDev.net forum for discovering a few of the bugs that have been fixed this time.

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

This topic is closed to new replies.

Advertisement