Fengari - Webブラウザ/nodeで動作するLua VM
JavaScriptはWebブラウザ上での動作が保証された唯一のプログラミング言語です。しかし、JavaScriptが好きではない方もたくさんいます。特にサーバサイドと別な言語で書かなければならないのが嫌という方はいるでしょう。 もしあなたが好きなプログラミング言語がLuaであれば、Fengariを使って記述してみてはいかがでしょう。
Fengariの使い方
Fengariでアラートを出すコードです。
local js = require "js"
local window = js.global
window:alert("Hello from Fengari!")
さらにdocumentからデータを取得する場合。
local js = require "js"
local window = js.global
local document = window.document
print("Document's title: " .. document.title)
非同期処理も書けます。
local js = require "js"
local window = js.global
local function sleep(delay)
local co = assert(coroutine.running(), "Should be run in a coroutine")
window:setTimeout(function()
assert(coroutine.resume(co))
end, delay*1000)
coroutine.yield()
end
coroutine.wrap(function()
print "Going to sleep now..."
sleep(3)
print "Sleep well?"
end)()
FengariはLua VMであり、Webブラウザまたはnode上で動作します。JavaScriptと比べてそれほど大きく変わるわけではありませんが、Luaらしく書けるでしょう。元の言語とそれほど変わりませんので、学習コストは大きくなさそうです。
FengariはJavaScript製のオープンソース・ソフトウェア(MIT License)です。
Fengari fengari-lua/fengari: ? φεγγάρι - The Lua VM written in JS ES6 for Node and the browser