luajls is a set of Lua modules for developing stand-alone Lua applications.
The modules provide general-purpose functions such as class definition and promise, to operating system abstractions such as file system and network access. The modules support asynchronous I/O based on an event loop.
The main targeted operating systems are Linux and Windows.
luajls provides:
- language basics such as class definition, serialization, logging, exception, promise, event loop, buffer, lock, threads, processes
- file system manipulation, I/O, file and networking access, serial communication, pipe, streams
- TCP, UDP, HTTP, HTTP/2, WebSocket, MQTT client and server with support for secured communication using SSL
- utility modules for queue, list and map, date and time, JSON and XML formats, codec, message digest, deflate
advanced utility modules for ZIP and tar files, GPIO, AST, scheduling, worker and web view
The following is the hello world HTTP server script.
local event = require('jls.lang.event')
local HttpServer = require('jls.net.http.HttpServer')
local httpServer = HttpServer:new()
httpServer:bind('::', 8000)
httpServer:createContext('/', function(exchange)
local response = exchange:getResponse()
response:setBody([[<!DOCTYPE html>
<html>
<body>
<p>It works !</p>
</body>
</html>
]])
end)
event:loop()
luajls supports the async/await pattern.
local event = require('jls.lang.event')
local Promise = require('jls.lang.Promise')
local HttpClient = require('jls.net.http.HttpClient')
local function nodePattern(name)
local namePattern = string.gsub(name, '%a', function(a) return '['..string.lower(a)..string.upper(a)..']' end)
return '<%s*'..namePattern..'%s*>%s*([^<]*)%s*<%s*/%s*'..namePattern..'%s*>'
end
Promise.async(function(await)
local client = HttpClient:new('http://www.lua.org')
local response = await(client:fetch('/'))
local body = await(response:text())
client:close()
print(string.match(body, nodePattern('title')))
end)
event:loop()
Just drop the jls folder in your Lua path.
The only required dependency is Lua. Optional dependencies are C-based or plain Lua modules such as luafilesystem, luasocket, luv, lua-openssl, lua-cjson. By example, the file system manipulation requires one of the luafilesystem or the luv dependent module. The recommended dependency is luv as it will provide you a uniform support of the io, lang and net packages.
Executable files:
- The release assets contain archives with all the required libraries.
The default, shared, archive contains the Lua interpreter, the C modules as shared libraries and the Lua modules. The static archive contains a single executable with all the required dependencies. - luajls is available on winget
winget install luajls
- luajls is also available on LuaRocks.
As luajls is composed of Lua modules, you need to adapt the environment variables LUA_PATH and LUA_CPATH to include the luajls home directory.
Lua, luajls and all the dependencies are available in the Lua C libraries repository.
The only fully supported version is the latest, currently Lua 5.4.
In order to support the majority of Lua engines, an effort is made to provide a good level of compatibility for Lua 5.1 and LuaJIT. Lua 5.1 compatibility is achived by using a transcompiler and is available in the respective 5.1 releases, the default code base is not fully compatible with Lua 5.1.
Browse the examples or applications such as Fast Cut and Light Home Automation.
Read the user manual or the API documentation.
Download binaries or access the source code.