GameMonkey Script

GameMonkey Script Forums
It is currently Tue Mar 19, 2019 7:05 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Mon Nov 30, 2009 8:18 pm 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
I just use global, it should work. Problem is there is no constant support in the language, so ultimately you are binding enumerations that have no protections against being changed. You can use a user table type that doesn't have a setdot defined, to prevent overwriting.


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 10, 2010 9:43 pm 
Offline

Joined: Sun Feb 07, 2010 3:01 pm
Posts: 1
DrEvil-OB wrote:
Code:
gmBind2::Class<gcn::Widget>("Widget",_m)
      .func(&gcn::Widget::isVisible,            "IsVisible")
      .func(&gcn::Widget::setVisible,            "SetVisible")
      .func(&gcn::Widget::setWidth,            "SetWidth")
      .func(&gcn::Widget::getWidth,            "GetWidth")
      ;

   gmBind2::Class<gcn::Button>("Button",_m)
      .base<gcn::Widget>()
      .constructor(Button_Ctr,0,"Gui")
      .func(&gcn::Button::setCaption,            "SetCaption")
      .func(&gcn::Button::getCaption,            "GetCaption")
      ;



What gmType user type you use in Button_Ctr? Simple example:
Code:
int Button_Ctr(gmThread* thread)
{
    if (thread->GetNumParams() == 0) {
        gcn::Button* btn = new gcn::Button();
        thread->PushNewUser(btn, ????);
        return GM_OK;
   }
   // ...etc
}


I'm asking about second argument of PushNewUser(). Can you write simple example? Thank you.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 11, 2010 4:17 am 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
you'll want to use the gmBind functions to push the binds

Code:
int Button_Ctr(gmThread *a_thread)
{
   GM_STRING_PARAM(txt,0,"");
   gmBind2::Class<gcn::Button>::PushObject(a_thread,new gcn::Button(txt),true);
   return GM_OK;
}


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 06, 2012 1:50 pm 
Offline

Joined: Tue Jan 31, 2012 7:53 am
Posts: 12
I tried using gmscriptex for the first time, but I couldnt compile because of errors on these lines:
Code:
template <>
inline gmVariable ToGmVar<bool>(bool &a_var) ...
template <>
inline gmVariable ToGmVar<int>(int &a_var) ...
template <>
inline gmVariable ToGmVar<float>(float &a_var) ...
template <>
inline gmVariable ToGmVar<float*>(float *&a_var) ...


gmbinder2.h:229:20: error: no function template matches function template specialization 'ToGmVar' [2]
gmbinder2.h:234:20: error: no function template matches function template specialization 'ToGmVar' [2]
gmbinder2.h:239:20: error: no function template matches function template specialization 'ToGmVar' [2]
gmbinder2.h:245:20: error: no function template matches function template specialization 'ToGmVar' [2]

im not familiar with function template specialization, anyone has a clue? thanks.
ps: im on mac and using Xcode as the IDE.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 07, 2012 4:35 pm 
Offline

Joined: Tue Jan 31, 2012 7:53 am
Posts: 12
Ok, I got rid of that problem by rewriting:
Code:
   __attribute__((noreturn)) inline gmVariable ToGmVar(T&) {}

to this:
Code:
    inline gmVariable ToGmVar(T& a) { return gmVariable(a); }


I dont know why __attribute__((noreturn)) and template specialization dont work together in g++ compiler.

Anyway, how do I bind a function which returns an user object or user defined class/type?
Looking at the example for std::string, I thought it should be automatically handled by the template system,
but when I tried to bind any function with custom return values (other than primitives), the compiler complain about a_operands[0] doesnt have 'Get' member function.

for instance:
Code:
class A {
   float x, y;
   std::string name;
};

class B {
public:
   A myA;
   A GetA() { return A(); }
};
gmBind2::Class<A>("A", machine).constructor().var(&A::x, "x").var(&A::y, "y").var(&A::name, "name");
gmBind2::Class<B>("B", machine).constructor().var(&B::myA, "a").function(&B::GetA, "GetA");


It didnt work..


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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