const float pi = float(M_PI);r = engine->RegisterGlobalProperty("const float PI", (void*)π); assert( r >= 0 );
You need to cast to void*, in order to remove the const from the variable. Since the property is registered as const with the script engine, this is still safe.
As for your question about passing an object pointer to the script function: Deyja already gave you a couple of possible solutions, I'll give you a couple more. If the script function is registered to receive the particle object by reference, you can pass the pointer directly, as pointers and references are basically the same thing. Just make sure that the pointer is pointing to a valid object. If you don't want to deal with object handles (which requires a slight overhead of reference counting), nor wish to use the old 1.10.1d version that support pointers, you could register a special type that will hold the pointer to the particle object. You can then register methods on this type that manipulates the object directly. Here's a short example on how that could be done:
engine->RegisterObjectType("particle_ptr", sizeof(Particle*), asOBJ_PRIMITIVE);engine->RegisterObjectBehaviour("particle_ptr", "void f()", asFUNCTION(constructor), asCALL_CDECL_OBJLAST);engine->RegisterObjectMethod("particle_ptr", "void SetPos(float x, float y)", asFUNCTION(setPos), asCALL_CDECL_OBJLAST);void constructor(Particle**p){ // Set the pointer to 0, so that an uninitialized variable won't point to invalid particle objects *p = 0;}void setPos(float x, float y, Particle**p){ if( *p ) (*p)->SetPos(x,y);}
Although this is fully valid, you'll have to be careful to make sure that the scripts do not access invalid particle pointers. A script could for example store a particle_ptr in a global variable, and if the application then deletes the particle object, the particle_ptr in the global variable would be pointing to an invalid object.