Advertisement

Register void* property

Started by May 23, 2012 08:25 PM
3 comments, last by saejox 12 years, 6 months ago
Hi,

is registering void* as property possible?


class Obj
{
void *data;
};

r = engine->RegisterObjectProperty("Obj", "what to write here?", offsetof(Obj, data));


then i cast it to other script handle in the script.

like this

Npc @mynpc = cast<Npc>(data);

if this is not possible i could write my own caster in c++

i must do this because; i get callbacks from physics engine by storing objects as void* inside rigid bodies. i need to pass them to script and use them somehow.

thank you.
If the void* is really pointing to the Npc type, then you can register the property as Npc@. Be aware that the script engine might call the Addref / release behaviours on this property if the handle is reassigned from the script.

It is probably safer to provide a couple of property accessor methods rather than registering the actual data property. The property accessor methods can then do the necessary conversions and memory management needed to guarantee correct access to the property.

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

Advertisement

If the void* is really pointing to the Npc type, then you can register the property as Npc@. Be aware that the script engine might call the Addref / release behaviours on this property if the handle is reassigned from the script.

It is probably safer to provide a couple of property accessor methods rather than registering the actual data property. The property accessor methods can then do the necessary conversions and memory management needed to guarantee correct access to the property.


as i understand it, it doesn't matter what what i register void* as?
so i try to do this,


r = engine->RegisterObjectProperty("RigidBody", "Npc @obj", offsetof(RigidBody, obj)); // obj is void*


i get this error during compilation
"Invalid Configuration. Verify the registered application interface, Build Module Error"

RigidBody is registered, RigidBody::obj exists and it is public.

Should use int* instead of void*? then register as "int @obj" ?
Did you register the Npc type before the property? Otherwise AngelScript obviously won't recognize it.

AngelScript doesn't know the real type of the C++ object property. If you tell AngelScript the type is an 'Npc @' then AngelScript will believe you, whether you're telling the truth or not. Of course, you'll have to make sure the object that the void* property points to really is an 'Npc' object, otherwise you'll be in trouble and will likely experience crashes as the script access the property.

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


Did you register the Npc type before the property? Otherwise AngelScript obviously won't recognize it.

AngelScript doesn't know the real type of the C++ object property. If you tell AngelScript the type is an 'Npc @' then AngelScript will believe you, whether you're telling the truth or not. Of course, you'll have to make sure the object that the void* property points to really is an 'Npc' object, otherwise you'll be in trouble and will likely experience crashes as the script access the property.


Thank you.
i was dumb enough to mess the order of registrations.

This topic is closed to new replies.

Advertisement