Coder Social home page Coder Social logo

anglhck's People

Contributors

bzar avatar cloudef avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

cloudef

anglhck's Issues

Getters where new reference is not returned

Functions like glhckCameraGetObject don't return new reference. But direct pointer to the object camera is holding, fails the bindings memory managment.

There are 2 solutions:
Wrap around the getters to always increment the glhck's reference counter.

glhckObject* glhckCameraGetObjectRef(camera) {
   return glhckObjectRef(glhckCameraGetObject(camera));
}

Other way is to register 2 datatypes, the reference counted type. And non reference counted type (think of a pointer).

static int registerGlhckObjectType(asIScriptEngine *engine, const char *obj, asDWORD flags)
{
  engine->RegisterObjectType(obj, 0, flags);
  if (!(flags & asOBJ_NOCOUNT)) {
     engine->RegisterObjectBehaviour(obj, asBEHAVE_ADDREF, "void f()", asFUNCTION(glhckObjectRef), asCALL_CDECL_OBJFIRST);
     engine->RegisterObjectBehaviour(obj, asBEHAVE_RELEASE, "void f()", asFUNCTION(glhckObjectFree), asCALL_CDECL_OBJFIRST);
  }
  engine->RegisterObjectMethod(obj, "void draw()", asFUNCTION(glhckObjectDraw), asCALL_CDECL_OBJFIRST);
  engine->RegisterObjectMethod(obj, "void setPosition(float x, float y, float z)", asFUNCTION(glhckObjectPositionf), asCALL_CDECL_OBJFIRST);
...
...
}

int anglhck::registerToEngine(asIScriptEngine *engine)
{
...
  registerGlhckObjectType(engine, "glhckObject", asOBJ_REF);
  registerGlhckObjectType(engine, "glhckObjectPtr", asOBJ_REF|asOBJ_NOCOUNT);
  engine->RegisterObjectMethod("glhckCamera", "glhckObjectPtr@ get_object()", asFUNCTION(glhckCameraGetObject), asCALL_CDECL_OBJFIRST);
...
}

With the pointer way, you introduce new datatype and complicate the memory managment in scripts. (You can crash application, if pointer is stored and used while the camera was freed).
You could make special method for glhckObjectPtr type that returns new reference from the pointer (by just doing glhckObjectRef) to workaround this.

The first way, needs bit more work (wrappers), but it would allow you to use only one type, and the scripter would not need to know about memory managment so much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.