Jump to content

  • Log In with Google      Sign In   
  • Create Account


alraz

Member Since 04 Sep 2005
Offline Last Active Jul 31 2012 06:50 PM
-----

Posts I've Made

In Topic: 2.24.0 GetFunctionByDecl returns NULL for functions inside a namespace

12 July 2012 - 11:57 AM

Yays!
Glad I was able to help a little this time, and not only point my finger to a problem Posted Image

In Topic: 2.24.0 GetFunctionByDecl returns NULL for functions inside a namespace

12 July 2012 - 06:14 AM

Great.

Thanks for the tip. I'll be sure to check it out later today

In Topic: 2.24.0 GetFunctionByDecl returns NULL for functions inside a namespace

11 July 2012 - 07:43 PM

Hello again!

I've been checking the source code and I think I have a few hints on what's going on.

First of all: the problem only occurs when the function who's pointer we want to retrive is inside a namespace AND it receives parámeters. If the function has no parameters, it's pointer is retrieved correctly.

The reason for that is that in as_module.cpp, around line 640, we have the following code:
if( globalFunctions[n]->objectType  == 0 &&
func.name					   == globalFunctions[n]->name &&
func.returnType				 == globalFunctions[n]->returnType &&
func.parameterTypes.GetLength() == globalFunctions[n]->parameterTypes.GetLength() &&
ns							  == globalFunctions[n]->nameSpace )
{
   //this means that the function we are looking for has been found!!

Take a close look at this line:
func.parameterTypes.GetLength() == globalFunctions[n]->parameterTypes.GetLength() &&

Turns out, when we search for a function inside a namespace, func.parameterTypes.GetLength() always returns 0.
And that's because in as_builder.cpp, around line 956, we have this code:
n = node->firstChild->next->next->next->firstChild;
while( n )
{
   //Do some parameter counting stuff here...

The problem is: when the function we are searching for is inside a namespace, "node->firstChild->next->next->next->firstChild;" returns null.
Why, you ask?
Damn I wish I knew... Posted Image I'd really love to know what that line of code actually does Posted Image

Could you help me out here, Andreas?
Why do you get the node's first child of the third sibling?

I really hope this is at least closing the distance to solve this weird issue

In Topic: Overrid C++ methods from angelscript, possible? alternatives?

11 July 2012 - 06:11 AM

Hello.

I asked the very same question to Andreas not long ago. And he told me of a work-around for this, (as well as why it doesn't work Posted Image ).

Here is his reply:


Unfortunately, it is not possible to inherit directly from application registered objects as they are not instances of asCScriptObject.

It is possible to implement a script proxy class that gives a light wrapper on top of the application registered object, and then have the script classes inherit from the proxy instead. For example:


shared class FSMProxy
{
FSMProxy() { @inner = FSM(); }
bool ChangeState(string v) { return inner.ChangeState(v); }
string CurrState {
get const { return inner.CurrState; }
set { inner.CurrState = value; }

private FSM @inner;
}


The script code for the proxy class can be generated by the application and added as a secondary script section to the script modules that will use the FSM class.

Regards,
Andreas



In this case "FSM" is my SuperClass and FSMProxy is the derived class

In Topic: 2.24.0 GetFunctionByDecl returns NULL for functions inside a namespace

09 July 2012 - 05:00 PM

EDIT: Fixed a stupid mistake of mine in the function implementation, now it almost works perfectly!! (look by the end)

Hello. If it helps... as in... at all... I've done the following changes:

Function registering (now it returns value instead of reference):
r = engine->RegisterGlobalFunction ("ref getFuncPtr (const string &in)", asFUNCTION (getFuncPtr), asCALL_CDECL); assert (r >= 0);

Function implementation (ID is now get with module->GetTypeIdByDecl to a fixed funcdef):


CScriptHandle getFuncPtr (const string &Name)
{
   CScriptHandle Handle;
   asIScriptFunction *Func = engine->GetModule(0)->GetFunctionByDecl (Name.c_str ());
   cout << Name << endl;
   cout << Func << endl;
   cout << engine->GetObjectTypeById (engine->GetModule(0)->GetTypeIdByDecl ("FSMFunc")) << endl;
   Handle.Set (Func, engine->GetObjectTypeById (engine->GetModule(0)->GetTypeIdByDecl ("FSMFunc")));

   return Handle;
}

and the script code goes like this (Notice that the function is called by the end):

funcdef void FSMFunc(TestClass @);

class TestClass
{
   string getMessage ()
   {
	  return "this is a message";
   }
}

void PrintMessage (TestClass @Class)
{
   print ("We got a message: " + Class.getMessage ());
}


void main ()
{
   TestClass Test;
   FSMFunc @Func = cast <FSMFunc @> (getFuncPtr ("void PrintMessage (TestClass @)"));

   Func (Test);
}


Aaaand, the grand result iiiis~

void PrintMessage (TestClass @)
0056BAA0
0054AB34
We got a message: this is a messageCall


So, that part is now working perfectly.
BUT!
If in the script we try to get a pointer to a function inside a namespace, the result is a null pointer.
Example code:
funcdef void FSMFunc(TestClass @);

class TestClass
{
   string getMessage ()
   {
	  return "this is a message";
   }
}

namespace test
{
   void PrintMessage (TestClass @Class)
   {
	  ::print ("We got a message: " + Class.getMessage ());
   }
}

void main ()
{
   TestClass Test;
   FSMFunc @Func = cast <FSMFunc @> (getFuncPtr ("void test::PrintMessage (TestClass @)"));

   Func (Test);
}

That script code gives us the following output:

void test::PrintMessage (TestClass @)
00000000
0016AB34

So, it seems like GetFunctionByDecl is not taking namespaces into account... maybe?

PARTNERS