bzar / anglhck Goto Github PK
View Code? Open in Web Editor NEWAngelScript bindings for glhck
AngelScript bindings for glhck
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.