Squirrel pointers

Discussion about everything. New games, 3d math, development tips...
Post Reply
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Squirrel pointers

Post by 3DModelerMan »

Hey, I want to return a pointer to one of my objects (or maybe a reference) to Squirrel. I need to provide access within Squirrel to the character class that I wrote. I'm using sqrat. So far I have this:

Code: Select all

//===========================================================================
 //Characters

 //Character enums
 Sqrat::Enumeration allegiances(*scriptMgr->getVM());
 allegiances.Const("Playable", EA_PLAYABLE);
 allegiances.Const("Enemy", EA_ENEMY);
 allegiances.Const("FriendlyNPC", EA_FRIENDLY_NPC);

 Sqrat::ConstTable(*scriptMgr->getVM()).Enum("Allegiance", allegiances);

 //Character class
 Sqrat::Class<ICharacter> characterClass(*scriptMgr->getVM());

 characterClass.Func("GetHealth", &ICharacter::getHealth);
 characterClass.Func("IsDead", &ICharacter::isDead);
 characterClass.Func("GetAllegiance", &ICharacter::getAllegiance);

 characterClass.Func("DrawMeleeWeapon", &ICharacter::drawMeleeWeapon);
 characterClass.Func("SheathMeleeWeapon", &ICharacter::sheathMeleeWeapon);
 
 characterClass.Func("SetPosition", &ICharacter::teleport);
		
 Sqrat::RootTable(*scriptMgr->getVM()).Bind("Character", characterClass);


//Get character by name
 characterTable.Func("GetCharacterByName", &sqGetCharacterByName);

 Sqrat::RootTable(*scriptMgr->getVM()).Bind("Characters", characterTable);
and the function that returns the character object is this:

Code: Select all

extern ICharacter* sqGetCharacterByName(Sqrat::string name);
How can I do this or something similar with sqrat? I really need to be able to expose this function.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Post Reply