Jump to content
  • Advertisement

kf6kjg

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

100 Neutral

About kf6kjg

  • Rank
    Newbie

Personal Information

  1. kf6kjg

    More AngelScript binding wrappers

    Ok, my code now seems to be sane: my test script runs without complaint. Even the test.cpp file looks normal, now that I have the correct header and understanding. Thank you both very much for the pointers in the correct direction! For reader learning: Switched over to using CALLER and CALLER_PR, eg: ret = engine->RegisterObjectMethod("Entity", "void ChangeScale(float)", CALLER(Entity, ChangeScale), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "float GetWorldScale()", CALLER(Entity, GetWorldScale), asCALL_CDECL_OBJFIRST); assert(ret >= 0); //... ret = engine->RegisterObjectMethod("Entity", "Rotation GetWorldRotation()", CALLER(Entity, GetWorldRotation), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void SetRotation(float, float, float)", CALLER_PR(Entity, SetRotation, (float, float, float), void), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void ChangeRotation(float, float, float)", CALLER_PR(Entity, ChangeRotation, (float, float, float), void), asCALL_CDECL_OBJFIRST); assert(ret >= 0); And I had to register via property accessors instead of direct properties, eg: ret = engine->RegisterObjectMethod("Entity", "const int& get_id() const", REF_GETTER(Entity, id), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void set_id(const int& in)", REF_SETTER(Entity, id), asCALL_CDECL_OBJFIRST); assert(ret >= 0);
  2. kf6kjg

    More AngelScript binding wrappers

    I've propagated the changes to the python files, here's the patch: [attachment=7476:wrapper_gen.patch.txt] Now that I've run those python files to regenerate the headers I'm going to re-attempt my code, I'll let you know the results.
  3. kf6kjg

    More AngelScript binding wrappers

    Bypassing the null problem worked. But now my entire stack of cards seems to have fallen down: the script sptr heads off to uninit'd memory. I'm probably missing something simple again, but after several hours of work, I've made little progress. File: sptrtypes.h // Library Includes #include <angelscript/sptrwrapper/as_smart_ptr_wrapper.h> // Local Includes #include "../sharedbase/Entity.h" // Forward Declarations // Typedefs // Functions // Helper functions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ template <typename T> void construct(void* address) { new (address) T(); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ template <typename T> void destroy(T* object) { object->~T(); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ template <typename T> void copy_construct(void* address, T* other) { new (address) T(*other); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ template <typename T> void assign(T * lhs, T* rhs) { *lhs = *rhs; } // Registration functions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void RegisterEntity(asIScriptEngine* const engine) { int ret = 0; // Register Object ret = engine->RegisterObjectType("Entity", sizeof(EntitySPTR), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK); assert(ret >= 0); // Register behaviors and operations ret = engine->RegisterObjectBehaviour("Entity", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Entity::FactoryAtAddress), asCALL_CDECL_OBJFIRST); assert(ret >= 0); // ret = engine->RegisterObjectBehaviour("Entity", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(construct<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectBehaviour("Entity", asBEHAVE_CONSTRUCT, "void f(const Entity &in)", asFUNCTION(copy_construct<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectBehaviour("Entity", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(destroy<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "Entity &opAssign(const Entity &in)", asFUNCTION(assign<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); // Register properties ret = engine->RegisterObjectProperty("Entity", "int id", offsetof(Entity, id)); assert(ret >= 0); ret = engine->RegisterObjectProperty("Entity", "PropertyMap properties", offsetof(Entity, properties)); assert(ret >= 0); ret = engine->RegisterObjectProperty("Entity", "float scale", offsetof(Entity, scale)); assert(ret >= 0); ret = engine->RegisterObjectProperty("Entity", "Vector positionOffset", offsetof(Entity, location)); assert(ret >= 0); ret = engine->RegisterObjectProperty("Entity", "Rotation rotationOffset", offsetof(Entity, rotation)); assert(ret >= 0); // Register methods ret = engine->RegisterObjectMethod("Entity", "void SetParent(Entity)", asMETHOD(Entity, SetParent), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "Entity GetParent()", asMETHOD(Entity, GetParent), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void ChangeScale(float)", asMETHOD(Entity, ChangeScale), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "float GetWorldScale()", asMETHOD(Entity, GetWorldScale), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "Vector GetWorldPosition()", asMETHOD(Entity, GetWorldPosition), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void SetWorldPosition(float, float, float)", asMETHODPR(Entity, SetWorldPosition, (float, float, float), void), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void ChangePosition(Vector)", asMETHODPR(Entity, ChangePosition, (D3DXVECTOR3), void), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "Rotation GetWorldRotation()", asMETHOD(Entity, GetWorldRotation), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void SetRotation(float, float, float)", asMETHODPR(Entity, SetRotation, (float, float, float), void), asCALL_THISCALL); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "void ChangeRotation(float, float, float)", asMETHODPR(Entity, ChangeRotation, (float, float, float), void), asCALL_THISCALL); assert(ret >= 0); } Note: Entity has a private ctor. Entity::Factory /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /// Creates a new Entity at the specified address. void Entity::FactoryAtAddress(void* address) { new (address) EntitySPTR(new Entity()); } Everything compiles fine, but when my test script runs, it has some strange crashes involving access violations in seemingly unrelated code. Test Script" void main(void) { Log(FLOW, "main: Loadup script started."); string test; { //Entity myEntity; Entity myEntity; myEntity.id = -12; // Access violation below involving a std::string when this is used. // myEntity.id = 12; // Execution proceeds fine with this one. } { test = "Entity without parens"; // This string is the one that gets the violation. Entity myEntity; Log(INFO, test + ": id is '" + myEntity.id + "' giving result: " + (myEntity.id == -1)); // Entity's ctor initializes this property to -1, so if this is pointed at the correct section of memory, one of these tests should return true. However, all return false. } { test = "Entity with parens"; Entity myEntity(); Log(INFO, test + ": id is '" + myEntity.id + "' giving result: " + (myEntity.id == -1)); } { test = "Entity with assignment of ctor"; Entity myEntity = Entity(); Log(INFO, test + ": id is '" + myEntity.id + "' giving result: " + (myEntity.id == -1)); } } This looks like VERY strange behavior to me, resulting in me coming to the conclusion that something in the registration is still wrong. Especially as it seems that I'm not even using anything from the as_smart_ptr_wrapper header...
  4. kf6kjg

    More AngelScript binding wrappers

    Ah, I was so distracted by the example main that I forgot to try the simple route - you are correct that I am using the native calling convention. asMETHOD and asCALL_THISCALL worked like a charm, thanks! Now that that's in place and I've cleaned out all the @'s in my code, (I'm converting my system over to SPTRs from normal pointers,) now all I have left is to figure out how to work around the fact that while I can assign null to these, I can't compare to null: I can't find any info on how to overload the "is null" operator! :/ The reason is that my script has a function with an optional parameter that is defaulted to null: // Yes, this isn't a C&P from my code; the code's too verbose for this example. void myFunc(const string &in name, Entity entity = null) { //... if (!(parent_entity is null)) { //... } //... } (The above code fails AS compilation with "No conversion from '<null handle>' to 'Entity' available.") I'm thinking I might just overload the function with one that doesn't have the second option and just have one call the other. (Or, as these are actually constructors in a script class in my actual code, have both of them call a private method that does the work...)
  5. kf6kjg

    More AngelScript binding wrappers

    Andreas, the available D/L currently has older non-G++/etc code still in it. Also, the example main.cpp still uses the older CALLER define, while the headers use WRAP_*. Which leads to a question for anyone to answer: how are those examples supposed to be written? The registration I'm using in my code keeps returning asWRONG_CALLING_CONV, aka the value -24, with no report from the callback. //[[From #include'd header]] class Entity; typedef std::shared_ptr<Entity> EntitySPTR; //[[From class Entity's declaration]] public: void ChangeScale(float); //... //[[From registration code]] int ret = 0; // Register Object ret = engine->RegisterObjectType("Entity", sizeof(EntitySPTR), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK); assert(ret >= 0); // Register behaviors and operations ret = engine->RegisterObjectBehaviour("Entity", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(construct<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectBehaviour("Entity", asBEHAVE_CONSTRUCT, "void f(const Entity & in)", asFUNCTION(copy_construct<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectBehaviour("Entity", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(destroy<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); ret = engine->RegisterObjectMethod("Entity", "Entity &opAssign(const Entity &in)", asFUNCTION(assign<EntitySPTR>), asCALL_CDECL_OBJFIRST); assert(ret >= 0); // Register methods ret = engine->RegisterObjectMethod("Entity", "void ChangeScale(float)", WRAP_MFN(Entity, ChangeScale), asCALL_CDECL_OBJFIRST); assert(ret >= 0); RegisterObjectMethod is returning -24, causing the assert to fail. I know that the manual recommends against looking at the return value for any debug help, but since the callback wan't reporting anything... Thanks for the info, and to all of you for the work required to make this in the first place!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!