Files
hakorune/examples/plugin_box_as_arg_demo.hako

35 lines
1.1 KiB
Plaintext
Raw Normal View History

// プラグインBoxが箱を引数に取る例のデモ
// HttpServer/Request/Responseの例
local server = new HttpServerBox()
server.start(8080)
// acceptはHttpRequestBoxを返す
local request = server.accept() // returns box
// HttpResponseBoxを作成
local response = new HttpResponseBox()
response.setStatus(200)
response.setHeader("Content-Type", "text/plain")
response.write("Hello from Nyash!")
// ★ HttpRequestBox.respond()はHttpResponseBox別の箱を引数に取る
request.respond(response) // Box引数の実例
// 他の例ArrayBoxにプラグインBoxを格納
local array = new ArrayBox()
local file1 = new FileBox()
local file2 = new FileBox()
// ArrayBoxは任意のBoxを引数に取れる
array.push(file1) // FileBoxプラグインBoxを引数に
array.push(file2) // 別のFileBoxインスタンスも
// MapBoxでも同様
local map = new MapBox()
local net = new HttpClientBox()
// MapBoxも任意のBoxを値として設定できる
map.set("client", net) // HttpClientBoxプラグインBoxを引数に
print("Plugin boxes can take other boxes as arguments!")