Graf Zahl wrote:Namespacing would certainly be nice but the way class name lookup works is plain and simply not possible. It would require some hefty refactoring in critical code.
Could you elaborate on this? Since I can think of plenty of ways to implement namespacing that shouldn't require many changes. For example, say you have this syntax:
Example file A:
Code: Select all
namespace SomeMod
{
class A // real name: SomeMod.A
{
}
}
Example file B:
Code: Select all
import SomeMod;
import AnotherMod;
class B
{
void Example()
{
A a = new("A");
}
}
Internally, the class lookup should do something like iterate over all class names and see if any match "A". If none match directly, look at all imports currently in scope (SomeMod, AnotherMod) and prepend them, thus doing a second search for SomeMod.A, a third search for AnotherMod.A if that fails, etc...
As for when class names are resolved at runtime, they just simply need to be fully qualified. For example:
Code: Select all
string className = "A";
class classType = className;
Would be invalid, (classType would be null), but:
Code: Select all
string className = "SomeMod.A";
class classType = className;
Would work as expected.
(It should be noted that while namespaces solve the issue of name conflicts amongst
different mods, it doesn't necessarily solve the problem for libraries, which are often embedded directly. In this case, something akin to what Gez suggested could be used in combination with namespaces.)
[quote="Graf Zahl"]Namespacing would certainly be nice but the way class name lookup works is plain and simply not possible. It would require some hefty refactoring in critical code.[/quote]
Could you elaborate on this? Since I can think of plenty of ways to implement namespacing that shouldn't require many changes. For example, say you have this syntax:
Example file A:
[code=php]namespace SomeMod
{
class A // real name: SomeMod.A
{
}
}[/code]
Example file B:
[code=php]import SomeMod;
import AnotherMod;
class B
{
void Example()
{
A a = new("A");
}
}[/code]
Internally, the class lookup should do something like iterate over all class names and see if any match "A". If none match directly, look at all imports currently in scope (SomeMod, AnotherMod) and prepend them, thus doing a second search for SomeMod.A, a third search for AnotherMod.A if that fails, etc...
As for when class names are resolved at runtime, they just simply need to be fully qualified. For example:
[code=php]string className = "A";
class classType = className;[/code]
Would be invalid, (classType would be null), but:
[code=php]string className = "SomeMod.A";
class classType = className;[/code]
Would work as expected.
(It should be noted that while namespaces solve the issue of name conflicts amongst [i]different mods[/i], it doesn't necessarily solve the problem for libraries, which are often embedded directly. In this case, something akin to what Gez suggested could be used in combination with namespaces.)