www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Behavior of __FILE__ in mixin template

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

I thought a mixin template is copied into the place where the 
mixin statement
exists and then the coding is evaluated.
This seems not to be true for __FILE__

I have a module form, which has a class Form. This module also 
contains
following mixin template

mixin template formTemplate()
{
	void generateForm()
	{
		string getFormName(string file =  __FILE__)()
		{
			import std.string: indexOf;
			return file[0..file.indexOf(".")]~".frm";
		}

		enum fileContent = import(getFormName());
	}
}

In another module myform I have a class MyForm in which I call 
the mixin statement:
mixin formTemplate.

The purpose of the template coding is: The enum fileContent 
should contain
the text of a file, which has the same name as the module but the 
file ending .frm.

I tried different things, but either it doesn't compile or 
__FILE__ returns "form"
instead of "myform".

Is this behavior correct? Do you have any tip?

Kind regards
André
Jun 22 2016
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 06/22/2016 10:07 AM, Andre Pany wrote:
 Hi,

 I thought a mixin template is copied into the place where the mixin
 statement
 exists and then the coding is evaluated.
 This seems not to be true for __FILE__
Apparently its the whole template that supports that. Is moving the 'file' parameter to the entire template acceptable? mixin template formTemplate(string file = __FILE__) { // ... } Ali
Jun 22 2016
parent Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 22 June 2016 at 17:52:26 UTC, Ali Çehreli wrote:
 On 06/22/2016 10:07 AM, Andre Pany wrote:
 Hi,

 I thought a mixin template is copied into the place where the
mixin
 statement
 exists and then the coding is evaluated.
 This seems not to be true for __FILE__
Apparently its the whole template that supports that. Is moving the 'file' parameter to the entire template acceptable? mixin template formTemplate(string file = __FILE__) { // ... } Ali
Perfekt, thanks a lot. Kind regards André
Jun 22 2016