Advertisement

Imports in namespace

Started by May 20, 2014 05:02 PM
8 comments, last by cvet 9 years, 7 months ago

Hello.

For now imports placed in global namespace, despite on named namespace where it's placed.
My preposition is include imports to appropriate namespaces, where it was placed.
Example:


namesace a
{
	import void Foo() from "module";
	import void Foo2() from "module";
}
namesace b
{
	import void Foo() from "module"; // Error for now, but must be ok after changes
	
	void Foo3()
	{
		Foo2(); // Ok for now, but must will be a::Foo2() after changes
	}
}

It makes sense. I'll look into it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

I've implemented this in revision 2084.

Thanks,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

It's work not as expected.

For now I can't import function from global namespace in some named namespace.

This code must work:


module1
int Foo1() { return 1; }
int Foo2() { return 2; }

module2
namesace A
{
	import int Foo1() from "module1";
	import int Foo2() from "module1";
}
namesace B
{
	import int Foo1() from "module1";
	
	void Test()
	{
		assert( Foo1() == A::Foo1() );
		assert( A::Foo2() == 2 );
	}
}

BindAllImportedFunctions() cannot guess how you want to bind the functions. It will only match functions that are declared exactly the same way in the source module as the import is declared in the destination module, including the namespace.

If you want to match functions in a different way, then you can do so by manually binding the functions using BindImportedFunction() instead.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Ok, you be able to do as you think is right, but there is not what I request in first post.

And for now I can't import function in some named namespace from different module and it's broke backward compatability.

module1

void foo(){}

module2

namespace NS{ import foo() from "module1"; } // error

Advertisement

I'm sorry. I guess I misunderstood your original post.

I understand now that what you want is to import a function into a different namespace than where it had been declared in the original module.

I should be able to at least allow BindAllImportedFunctions do a recursive search in parent namespaces, but if you want to allow the import from an unrelated namespace then you really do have to implement the matching logic by yourself.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Yes, I will write my custom function importer.

Thanks!

I've added the support for recursively searching parent namespaces in revision 2119.

It should work more like you had originally requested now.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Yes, thanks, this help!

This topic is closed to new replies.

Advertisement