Show Changes Show Changes
Edit Edit
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Rename Rename
Administration Page Administration Page
Topic Locks Topic Locks



6/30/2007 1:02:01 PM
5/30/2007 12:38:04 PM
5/28/2007 6:50:31 AM
5/20/2006 12:03:14 PM
10/9/2005 4:16:57 PM
List all versions List all versions

RSS feed for the SquirrelWiki namespace

Passing Class Instances As User Pointers

Back to SqPlus


With the latest version of SqPlus you can pass instances of classes freely between C++ and Squirrel by value/copy or by reference/pointer (must use pointer syntax on the C++ side for function declarations). If the function to be bound uses reference syntax, the function must be cast to a version using pointer arguments:

// play(SoundEffect & se) is defined using pass value by reference. We'll cast it to pass a pointer,
// which is what the compiler does during compilation (thus the code works as intended when called back). This is required by
// the template system design as pass by reference behaves as pass by copy.
// SSoundSystem is created from the actual sound system and a custom sound system for script access via the binding method:



typedef int (SoundSystem::*PlaySoundEffectFunc)(SoundEffect * soundEffect);
SQClassDef sSoundSystem("SoundSystem");

#else // If the class instance does not need to be derefenced in script, it can be passed as an SQUserPointer to improve performance
      // or to keep the instance opaque to script:

typedef int (SoundSystem::*PlaySoundEffectFunc)(SQUserPointer soundEffect);
SQClassDef<SSoundSystem> sSoundSystem("SoundSystem");


SQClassDef<SGameSystem> sGameSystem("GameSystem");

#ifndef USE_USER_POINTERS // Use pointers to SoundEffect class/struct


#else // Use user pointers



// === In script ===

// Create instances during init:

soundSystem <- SoundSystem();
gameSystem  <- GameSystem();

// At runtime:; 

Not logged in. Log in

squirrel's community wiki

This is FlexWiki, an open source wiki engine.

Change Style

Recent Topics

The design style of the replica watches sale is a business movement. It is very suitable to replica watches wear during work or leisure sports. It is swiss replica watches an automatic mechanical movement with no extra design. It is different from a watch with a calendar, a tourbillon, etc. 819.315 is more Smooth and refreshing rolex replica.