GameMonkey Script

GameMonkey Script Forums
It is currently Fri Mar 22, 2019 9:57 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Jul 11, 2009 9:46 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
I think it would be nice if gmVariable looked like this:

Code:
class gmVariable
{

public:
  //Returns the int value, or cast the float value to int or returns defaultValue if neither
  int   Int(int defaultValue = 0) const;

  //Returns the float value, or cast the int value to float or returns defaultValue if neither.
  float   Float(float defaultValue = 0.0f) const;

  //Returns the c-string value if it's a gmStringObject, default value if not.
  const char*       CString(const char* defaultValue = "") const;

  //These ones return NULL if the variable isn't the right type
  gmStringObject*   StringObject() const;
  gmTableObject*    TableObject() const;
  gmFunctionObject* FunctionObject() const;
  gmUserObject*     UserObject(gmType type) const;
 
};


It makes binding easier and cleaner looking:

Code:
float x = a_thread->Param(0).Float();
float y = a_thread->Param(1).Float();
const char* text = a_thread->Param(2).CString("");

Graphics::Instance().DrawText(x, y, text);


You don't always have to check the type (unless it's one of the last four "object" types...then you need to check if it returns a NULL)


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 11, 2009 4:48 pm 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
That's already in there in the form of the "safe" functions, like GetIntSafe, GetFloatSafe, GetStringObjectSafe, etc


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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