最近TLでもよく見かけるようになったのでそろそろ書いてみようと思い
とりあえずioライブラリ使って定番の"hello, dart"を表示まで実装したので書き留めておく。
まずは公式サイトからdart sdkをダウンロードする...のでもいいんですけど、
dart editorのほうにはeditor、sdk、dartiumが含まれているのでそれをダウンロードする。
=> http://www.dartlang.org/docs/getting-started/editor/
自分にはdart editorが使い辛かったのでコマンドラインで実行するためにパスを通しておく。
$ unzip dart-macos.zip
$ mv dart /Applications
$ export PATH=$PATH:/Applications/dart/dart-sdk/bin
次にdart-modeをemacsに設定する
・githubからdart-mode.elをダウンロードしてくる
=> https://github.com/nex3/dart-mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Dart | |
(require 'dart-mode) | |
(add-to-list 'auto-mode-alist '("\\.dart$" . dart-mode)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#library("hellodart"); | |
#import("dart:io"); | |
final HOST = "127.0.0.1"; | |
final PORT = 8080; | |
void main() { | |
HttpServer server = new HttpServer(); | |
server.addRequestHandler((HttpRequest req) => true, handler); | |
server.listen(HOST, PORT); | |
print("helloworld on http://${HOST}:${PORT}."); | |
} | |
void handler(HttpRequest req, HttpResponse res) { | |
print("Request: ${req.method} ${req.uri}"); | |
res.headers.set(HttpHeaders.CONTENT_TYPE, "text/html; charset=UTF-8"); | |
res.outputStream.writeString("hello, dart"); | |
res.outputStream.close(); | |
} |
$ dart hellodart.dart
これでブラウザで http://127.0.0.1:8080/ にアクセスすると hello, dart と表示されます。
日本語リファレンスサイト
=> https://sites.google.com/site/dartrefjp/