...ing logging 4.0

はてなブログに移行しました。D言語の話とかいろいろ。

DFL

だいたいShooさんのPull Requestです。

DFL64はビルドがうまくいかなくて検証できず。

DFL for dmd 2.066

久しぶり。

import dfl;

pragma(lib, "dfl.lib");

class MainForm : Form {
	private Button _button;
	private ListBox _listbox;
	private MainMenu _menu;
	
	this() {
		_button = new TestButton();
		_button.text = "ok";
		_button.parent = this;
		_button.location = Point(100, 100);
		
		_listbox = new ListBox();
		_listbox.parent = this;
		_listbox.size = Size(60, 150);
		_listbox.items.add("foo");
		_listbox.items.addRange(["hoge", "piyo"]);
		_listbox.click ~= (Control c, EventArgs ea) { msgBox(_listbox.selectedItem.toString()); };
		
		_menu = new MainMenu();
		MenuItem item = new MenuItem();
		item.text = "File";
		MenuItem subItem = new MenuItem();
		subItem.text = "Open";
		auto menuClickHandler = (MenuItem mi, EventArgs ea){ msgBox("open the door"); };
		subItem.click ~= menuClickHandler;
		item.menuItems.add(subItem);
		_menu.menuItems.add(item);
		this.menu = _menu;
	}
}

class TestButton : Button {
	override void onClick(EventArgs ea) { // delegateでもoverrideでもおk
		msgBox("hi");
	}
}

void main() {
	Application.run(new MainForm());
}

関数と関数テンプレートのオーバーロード

今週の新技術

import std.stdio;

class A
{
	void f()      { writeln("f()") ;}
	void f(int)   { writeln("f(int)"); }
	void f(T)(T a){ writeln("f(", typeid(T), ")"); }
}

void main()
{
	A a = new A;
	a.f();
	a.f(1);
	a.f("str");
}
f()
f(int)
f(immutable(char)[])