Hello! In my projects, I frequently use AngelScript, and one limitation I’ve noticed is the absence of a "using namespace <name>" feature like in C++. This can make working with namespaces cumbersome at times.
To address this, I decided to implement my own support for it. It mostly works in a similar way to C++ (though function access has some differences). Here’s an example to illustrate:
void g_func() {}
namespace App
{
class Class{};
void func() { print("APP::FOO"); }
enum Enum {};
void g_func() {}
}
namespace Foo
{
void foo_example() {};
}
namespace Bar
{
using namespace App;
class Class{};
void func() { print("BAR::FOO"); }
enum Enum {};
void example1()
{
func(); // Error, multiple declaration (Bar::func and App::func)
g_func(); // Error, multiple declaration (g_func and App::g_func)
Enum a; // Ok, using Bar::Enum;
App::Enum b; // Ok, using App::Enum
}
void example2()
{
{
using namespace Foo;
foo_example(); // Ok, called Foo::foo_example();
}
foo_example(); // Error, foo_example is not visible here;
}
}
// If you change App to Bar in the next line, an error will occur because Bar will automatically inherit App namespace visibility.
using namespace App;
class A : Class {}; // Ok, parent is App::Class
The difference with the functions I mentioned earlier is that I haven’t yet figured out how to prioritize the namespace from which the function is called.
If this implementation is acceptable for public use, I will be happy to send a patch with the changes