Take a look at the \tests\test_feature_source\test_interface.cpp file in the SDK zip. It will probably have all the answers you need. Though the code is not meant to be a tutorial, so it may not be the nicest looking code ;)
Regards,
Andreas
C++ call AS class member function
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 looked at that file before, (that's how I got it working this far =)), it still never calls a C++ function passing an AS class that derrived from the interface.
Basically I need to:
C++
AngelScript:
I have no idea how to do that =\ I've tried using any, but I can't cast the any back to an object that can call methods on it. Hopefully this isn't too hard =)
Thanks a lot,
Shawn.
Basically I need to:
C++
void registerEntity(ASInstance i) { collection.push(i);}void updateAllEntities() { for each (entity in collection) { entity->callAngelScriptMethod("update"); }}
AngelScript:
class ASEntity : IEntity { ASEntity() { registerEntity(this); } void update() { //whatever }};
I have no idea how to do that =\ I've tried using any, but I can't cast the any back to an object that can call methods on it. Hopefully this isn't too hard =)
Thanks a lot,
Shawn.
Ah, you're right. My mistake.
Well, it's really quite simple:
When you're done with the entity, i.e. when you're removing it from the collection, you need to remember to call the Release method on the asIScriptStruct so that AngelScript can free the memory.
Regards,
Andreas
Well, it's really quite simple:
void registerEntity(asIScriptStruct *entity){ collection.push(entity);}engine->RegisterGlobalFunction("void registerEntity(IEntity @)", asFUNCTION(registerEntity), asCALL_CDECL);
When you're done with the entity, i.e. when you're removing it from the collection, you need to remember to call the Release method on the asIScriptStruct so that AngelScript can free the memory.
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
Fantastic. Working beautifully.
Thanks so much for your help. If I can interface the rest of my engine with AS and performance/stability is acceptable I'll be donating some $ =)
Thanks again,
-Shawn.
Thanks so much for your help. If I can interface the rest of my engine with AS and performance/stability is acceptable I'll be donating some $ =)
Thanks again,
-Shawn.
Great!
Let me know if you come upon any performance issues or anything else. I'm always looking for ways to improve the library.
Regards,
Andreas
Let me know if you come upon any performance issues or anything else. I'm always looking for ways to improve the library.
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
Popular Topics
Advertisement