Jump to content

[SOLVED] namespacing issue


photo

Recommended Posts

Hi, we have been using the 2011-12-28 version of the sdk until lately. We have been encountering some issues with namespacing from within the UnigineScripts with the newer version (2012-04-11, which we are aware is not the latest).

 

1. using keyword can only be used if the code is encapsulated within a namespace also.

 

with error (Interpreter::parse_prototype():can't find "myNamespace::subNamespace" namespace):

using myNamespace::subNamespace;
MyObject object;
int init() {

object = new MyObject();
return 1;
}

 

 

without error:

namespace World {
using myNamespace::subNamespace;

   MyObject object;
   int init() {

       object = new MyObject();
       return 1;
   }
}

 

2. the second code snippet would work but the interpreter cannot properly parse the world init because it is now contained within a namespace, instead we have to do this:

int init() {
return World::init();
}
namespace World {
using myNamespace::subNamespace;

   MyObject object;
   int init() {

       object = new MyObject();
       return 1;
   }
}

 

 

Is this intended behavior?

Link to comment

By the way, I have read the Unigine version announcements. For the 2012-04-11 version:

"using" keyword searches for a given namespace through all nested namespaces up to the global one instead of searching only in the global scope.

 

For the 2012-06-14 version:

 

Keyword using is now in the global namespace.

 

What are the implications of the above?

Link to comment

Hi Mandee,

 

It seems to work for me with this sample:

 

namespace myNamespace::subNamespace {
 class MyObject {
   public:
     int data;
 };
}

using Trick;
using myNamespace::subNamespace;

namespace Trick {
 int init() {

   MyObject obj = new MyObject();
   log.message("Hello, interpreter. Do you think that this is your init function? Nope. It's init from Trick namespace.\n");
   System::init();
   return 1;
 }
}

namespace System {
 int init() {

   log.message("Hello from System namespace.\n");
   return 0;
 }
}

 

I'm using last SDK. Could you give more details about your sample?

Link to comment

unclebob, I created a class which is contained within a namespace in a separate script file. Then I included its header file into my world script. If I use the "using" keyword in the world script, I get the error I mentioned above. But if I encapsulate the world script in its own namespace (World), "using" works just fine. Now in order for the world init(), update(), shutdown(), etc.. to be properly read by the interpreter, I now have to write a separate init(), update(), shutdown(), etc... which would invoke: return World::init(), etc. I need to provide the interpreter a way to access those functions which are now contained in the World namespace. I have now tested the namespacing and "using" keyword on three versions of the sdk: 2011-12-28, 2012-04-11, 2012-06-14.

 

I only encountered this issue with the 2012-04-11 version. I think it has been fixed in the latest version (2012-06-14).

Link to comment
×
×
  • Create New...