GameMonkey Script

GameMonkey Script Forums
It is currently Thu May 23, 2019 2:44 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Nov 20, 2004 4:18 pm 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
Howdy GameMonkers,

I'm happy to announce that gmBind version 0.9.0 is now ready for public beta testing.

gmBind is a template library that aims to facilitate the binding process of your native classes to the GameMonkey script environment.

gmBind 0.9.0 features:
* Easy binding of native classes to GM
* Custom get/set property functions - allows read/write access to native object properties
* Gain access to 'native' objects created in script - useful for using GameMonkey as an initialisation tool
* Port existing native objects to GameMonkey - useful if you need to expose your already existing game objects to script
* Allow your ported classes to be extended in script through addition of custom script propterties and functions. Extended properties can also be retreived / set in native code if needed
* Specify custom operators for your objects

There's a couple of small extras I'll be adding before the 1.0.0 release is out but the library is almost ready for some real usage.

Let's take a look at an example:

'bomb' - The simple native class to port to GM

Code:
// The native class

class bomb
{
public:

   bomb()
   {
      isExploded = 0;
   }

   // Explode the bomb - the bomb can only be exploded once before it needs
   // to be reset
   void explode()
   {
      if (!isExploded)
      {
         std::cout << "BOOM!" << std::endl;
         isExploded = 1;
      }
      else
      {
         std::cout << "Already exploded, dude" << std::endl;
      }
   }
   // Attribute flag to state whether the bomb has been exploded or not
   int isExploded;
};


Code:
class gmBomb   :   public gmBind< bomb, gmBomb >,
               public bomb
{
public:
   GMBIND_DECLARE_FUNCTIONS( );
   GMBIND_DECLARE_PROPERTIES( );

   static int gmExplode(gmThread * a_thread)
   {
      bomb* p = gmBomb::GetThisObject( a_thread );
      p->explode();
      return GM_OK;
   }

   static bool getExploded( bomb *p, gmThread * a_thread, gmVariable * a_operands )
   {
      a_operands[0].m_value.m_int = (p->isExploded ? 1 : 0);
      return true;
   }

   static bool setExploded( bomb *p, gmThread * a_thread, gmVariable * a_operands )
   {
      p->isExploded = (a_operands[1].m_value.m_int ? 1 : 0);
      return true;
   }
};

GMBIND_INIT_TYPE( gmBomb, "bomb" );
GMBIND_FUNCTION_MAP_BEGIN( gmBomb )
   GMBIND_FUNCTION( "explode", gmExplode )
GMBIND_FUNCTION_MAP_END();
GMBIND_PROPERTY_MAP_BEGIN( gmBomb )
   GMBIND_PROPERTY( "isExploded", getExploded, setExploded )
GMBIND_PROPERTY_MAP_END();
};


Now that the proxy class has been created, you need to call gmBomb::Initialise( a_machine ); and the type is now ready for use in your program.

Code:
// gm script code
boom = bomb();
boom.explode();   // BANG!
boom.explode();   // Already exploded!
boom.isExploded = 0;
boom.explode();   // BANG!

// Adding an extended property is as easy as it is in GM
boom.name = "BIG BOMB!";
print( boom.name );    // > BIG BOMB


You can download gmBind 0.9.0 from my website here. Full documentation and an example is provided in the gmBind.h header file. gmBind is released under the MIT license, so you're free to use it in any way you see fit.

Please feel free to leave me feedback about any questions, bugs, suggestions or improvements.

I hope this is useful to someone! It's certainly been useful to me.

Oli


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group