Could someone explain to me how to get namespacing in the QScriptEngine extensions? I've set it up so I have a directory foo/ under script/, with an __init__.js file being executed.

Here's my javascript file:

Qt Code:
  1. __setupPackage__(__extension__);
  2. print(__extension__);
  3.  
  4. hello = function() { return 5; };
To copy to clipboard, switch view to plain text mode 

And in my C++ code:

Qt Code:
  1. engine.evaluate("hello();"); // works fine
To copy to clipboard, switch view to plain text mode 

So my question is, what's the point of the file hierarchy like foo/bar/whatever (foo.bar.whatever), if they all get lumped into a global namespace? I've seen some examples, where they try to create a namespace in the code, but I can't seem to get that to work without getting a compiler error.

Qt Code:
  1. foo = {
  2. hello : function() { return 5; }
  3. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. engine.evaluate("foo.hello();");
To copy to clipboard, switch view to plain text mode 

Am I misunderstanding the way Qt handles namespaces? Should everything indeed be mashed into a global scope regardless of which file it was taken from? Is there a proper example for creating these type of namespaces? Thanks.