Jump to content
  • Advertisement
  • entries
    437
  • comments
    1000
  • views
    336843

gmObjectT 0.5PR

Sign in to follow this  
evolutional

161 views

I've got to version 0.5 of my gmObjectT template class for binding C++ classes to GameMonkey. It works in a very similar way to the one I've been writing for SpiderMonkey, which is nice considering they're very different languages interface-wise. I'm now wondering if I should polish up my Lua skills and port it over to that. GameMonkey is a very simlar language to Lua but has an infinitely better C++ API (stupid Lua stack). Something like this template library may really help a lot.

The current version's features are hard to classify as it's a binding helper and by definition it helps the C++ binding process along. It hides a lot of the script API specific stuff inside the template, allowing you to wrie a fairly simple wrapper class to handle the calling of functions and the getting/setting of properties. Each property can have a set/get method allowing you to specify read/write only properties with minimal fuss.

I'm looking to expand the system to handle the index operators (object[x]) as well as normal operators (+, -, /, *, etc) so the user can quickly add handling of these into their code with minimal effort. I've also been toying with the idea of throwing in some support for auto-casting the property 'set' calls. Most of the time, a C++ object will want a specific type and so it make sense to cast to this.

By way of example, here's a typical set method to set an int. GameMonkey will pass either an int or a float which needs converting for C++.


static bool setX( Alien *p, gmThread * a_thread, gmVariable * a_operands )
{
if ( a_operands[1].m_type == GM_INT )
{
p->x = (float) a_operands[1].m_value.m_int;
return true;
}
else if ( a_operands[1].m_type == GM_FLOAT )
{
p->x = a_operands[1].m_value.m_float;
return true;
}
return false;
}



If I introduce a typed system, I can change the method to make it simpler for binding.


static bool setX( Alien *p, gmThread * a_thread, gmVariable * a_operands, float *value )
{
p->x = value;
}




In this situation, a special 'set' handler will need writing to handle either the int, float or user type meaning that I can have one of 4 possible property calls (keeping the existing one for power-users and special cases and multiple values). The template code would have logic for dealing with the casting internally so the typical logic code is hidden away. I feel that this is necessary because most people will be dealing with single-value set calls and it's pretty annoying having to deal with the same cast on ints/floats. I'll have to think more about the actual implementation of this method (I can already see flaws here) but it sounds reasonable.

Incidentally, has anyone used GameMonkey at all? Would something like this be useful to you (in GM, SpiderMonkey or Lua?)
Sign in to follow this  


1 Comment


Recommended Comments

I've only ever really used lua properly. I'm still deciding what scripting language to use for the first version of my engine (I want to *eventually* write my own). I recently looked into Squirrel, you should check it out.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!