GameMonkey Script

GameMonkey Script Forums
It is currently Wed Jan 23, 2019 1:20 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Dec 10, 2015 7:54 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
I'm trying now to add support for this:

Code:
myFunc = function()
{
  for(i = 0; i < __params.Count; i += 1)
  {
    Console.WriteLine("Param: ", __params[i]);
  }
};

myFunc("String1", "String2", "String3");


I've had some success but as i do not know the back end too well for gmMachine, it may or may not have broken things (in gmThread). Right now the only obvious issue is getting __params.Count. Here's how i've implemented this addition.

First i changed in gmThread.cpp around line 1176:
Code:
  m_base = base;
  //m_top = base + fn->GetNumParamsLocals();
 
 
  ///CHANGE HERE
  if(a_numParameters > fn->GetNumParams())
   m_top = base + (a_numParameters + fn->GetNumLocals());
  else m_top = base + fn->GetNumParamsLocals();
  //END HERE


Then i made a new "type" called "Param". This "Param" type has a get index code that looks like this:
Code:
void GM_CDECL gmParamOpGetIndex(gmThread * a_thread, gmVariable * a_operands)
{
   //ParamLib::ParamObject* params = static_cast<ParamLib::ParamObject*>(a_operands[0].GetUserSafe(ParamLib::ParamObject::GetType()));

   if(a_operands[1].m_type == GM_INT)
   {
      int index = a_operands[1].m_value.m_int;
      //if(index >= 0 && index < a_thread->GetNumParams())
      //{
         a_operands[0] = a_thread->Param(index);
      //} else a_operands[0].Nullify();
   }
    else a_operands[0].Nullify();
}


This works, but what i can't get to work is __params.Count. here's the count for Get Dot:

Code:
void GM_CDECL gmParamOpGetDot(gmThread * a_thread, gmVariable * a_operands)
{
   //ParamLib::ParamObject* params = static_cast<ParamLib::ParamObject*>(a_operands[0].GetUserSafe(ParamLib::ParamObject::GetType()));

   if(a_operands[1].m_value.m_ref == gmstr_Count.m_value.m_ref)
      a_operands[0].SetInt(a_thread->GetNumParams());

    else a_operands[0].Nullify();
}


__params.Count returning 1 even from this function:

Code:
derp = function()
{
   Console.WriteLine("COUNT ", __params.Count);  //Returning 1. Should say 3..?
   Console.WriteLine("PARAM ", __params[0]); //Correctly prints "HELLO"
   Console.WriteLine("PARAM ", __params[1]); //Correctly prints "WORLD"
   Console.WriteLine("PARAM ", __params[2]); //Correctly prints "TEMP"
};

derp("HELLO", "WORLD", "TEMP");
Main.Run(PostLoadFunction);


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 10, 2015 8:08 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
Just realized in gmThread, "m_numParameters" is on set for a cFunction, not a script function. I changed it now to also be set for script functions, so it returns 3 in the above example.


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 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