Coder Social home page Coder Social logo

javalikescript / luajls Goto Github PK

View Code? Open in Web Editor NEW
43.0 6.0 2.0 1.9 MB

luajls is a set of Lua modules for developing stand-alone Lua applications

License: MIT License

Lua 99.67% Batchfile 0.24% Shell 0.09%
lua lua-modules linux windows standard-library

luajls's Introduction

ManualDocsDownloads

What is luajls?

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 event loops.

luajls stands on the shoulders of giants

The main targeted operating systems are Linux and Windows.

What are the features?

luajls provides:

  • language basics such as class definition, logging, exception, promise, event loop, threads, processes
  • file system manipulation, I/O, file and networking access, serial communication, pipe, streams
  • TCP, UDP, HTTP, WebSocket, MQTT client and server with support for secured communication using SSL
  • utility modules for list and map, date and time, JSON and XML formats, AST, codec, message digest, deflate, ZIP and tar files, scheduling, worker and web view

What does it look like?

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()

How to install and use it?

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.

Lua, luajls and all the dependencies are available in the Lua C libraries repository.

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.

luajls is available on winget

winget install luajls

luajls is also available on LuaRocks.

What are the supported Lua versions?

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.

What do you want to do?

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.

luajls's People

Contributors

javalikescript avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

marcweber

luajls's Issues

jls.net.http.WebSocket not found

I'd like to use luajls for websocket client. I tried this code:

local HttpServer = require('jls.net.http.HttpServer')
local WebSocket = require('jls.net.http.WebSocket')

HttpServer include works, but WebSocket not:

lua: test.lua:3: module 'jls.net.http.WebSocket' not found:
        no field package.preload['jls.net.http.WebSocket']
        no file '/usr/local/share/lua/5.3/jls/net/http/WebSocket.lua'
        no file '/usr/local/share/lua/5.3/jls/net/http/WebSocket/init.lua'
        no file '/usr/local/lib/lua/5.3/jls/net/http/WebSocket.lua'
        no file '/usr/local/lib/lua/5.3/jls/net/http/WebSocket/init.lua'
        no file '/usr/share/lua/5.3/jls/net/http/WebSocket.lua'
        no file '/usr/share/lua/5.3/jls/net/http/WebSocket/init.lua'
        no file './jls/net/http/WebSocket.lua'
        no file './jls/net/http/WebSocket/init.lua'
        no file '/usr/local/lib/lua/5.3/jls/net/http/WebSocket.so'
        no file '/usr/lib/x86_64-linux-gnu/lua/5.3/jls/net/http/WebSocket.so'
        no file '/usr/lib/lua/5.3/jls/net/http/WebSocket.so'
        no file '/usr/local/lib/lua/5.3/loadall.so'
        no file './jls/net/http/WebSocket.so'
        no file '/usr/local/lib/lua/5.3/jls.so'
        no file '/usr/lib/x86_64-linux-gnu/lua/5.3/jls.so'
        no file '/usr/lib/lua/5.3/jls.so'
        no file '/usr/local/lib/lua/5.3/loadall.so'
        no file './jls.so'
stack traceback:
        [C]: in function 'jls.lang.loader.BASE_REQUIRE'
        test.lua:3: in main chunk
        [C]: in ?

How can I fix this?

Luarocks package?

I was wondering if this project would ever get posted on luarocks, the lua package manager

Luarocks rockspec must be set to version 3

Error: Failed installing dependency: https://luarocks.org/luajls-0.7-3.rockspec - /var/folders/ps/cqv_3ytx5nn59k5q3k17th500000gn/T/luarocks_luarocks-rockspec-luajls-0.7-3-Z9gOFv/luajls-0.7-3.rockspec: Unknown field labels (using rockspec format 1.0 -- adding 'rockspec_format = "3.0"' to the rockspec will fix this)

Fixed rockspec:

rockspec_format = "3.0"
package = "luajls"
version = "0.7-3"
source = {
   url = "https://github.com/javalikescript/luajls/archive/refs/tags/0.7.3.zip",
   dir = "luajls-0.7.3",
}
description = {
   summary = "luajls is a set of Lua modules for developing stand-alone Lua applications",
   detailed = [[
      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 event loops.
      luajls provides:
      language basics such as class definition, logging, exception, promise, event loop, threads, processes
      file system manipulation, I/O, file and networking access, serial communication, pipe, streams
      TCP, UDP, DNS, HTTP, WebSocket, MQTT client and server with support for secured communication using SSL
      utility modules for list and map, date and time, JSON and XML formats, AST, codec, message digest, deflate, ZIP and tar files, scheduling, worker and web view
      The main targeted operating systems are Linux and Windows.
      For dependencies use rock module luajls-lfs or luajls-luv
   ]],
   homepage = "https://github.com/javalikescript/luajls",
   license = "MIT",
   labels = { "class", "event", "linux", "windows", "process", "filesystem", "http", "compression", "json", "dns", "xml", "websocket", "mqtt" },
}
dependencies = {
   "lua >= 5.4",
   "dkjson",
   "sha1",
   "xml2lua",
   "dumbluaparser",
   "luaunit", -- test dependency
}
build = {
   type = "builtin",
   modules = {
      ["jls.init"] = "jls/init.lua",
      ["jls.io.File"] = "jls/io/File.lua",
      ["jls.io.FileDescriptor"] = "jls/io/FileDescriptor.lua",
      ["jls.io.FileDescriptor-"] = "jls/io/FileDescriptor-.lua",
      ["jls.io.FileDescriptor-luv"] = "jls/io/FileDescriptor-luv.lua",
      ["jls.io.Path"] = "jls/io/Path.lua",
      ["jls.io.Pipe"] = "jls/io/Pipe.lua",
      ["jls.io.Pipe-luachild"] = "jls/io/Pipe-luachild.lua",
      ["jls.io.Pipe-luv"] = "jls/io/Pipe-luv.lua",
      ["jls.io.Serial"] = "jls/io/Serial.lua",
      ["jls.io.Serial-"] = "jls/io/Serial-.lua",
      ["jls.io.Serial-luv"] = "jls/io/Serial-luv.lua",
      ["jls.io.SerialBase"] = "jls/io/SerialBase.lua",
      ["jls.io.StreamHandler"] = "jls/io/StreamHandler.lua",
      ["jls.io.fs"] = "jls/io/fs.lua",
      ["jls.io.fs-lfs"] = "jls/io/fs-lfs.lua",
      ["jls.io.fs-luv"] = "jls/io/fs-luv.lua",
      ["jls.io.streams.BlockStreamHandler"] = "jls/io/streams/BlockStreamHandler.lua",
      ["jls.io.streams.BufferedStreamHandler"] = "jls/io/streams/BufferedStreamHandler.lua",
      ["jls.io.streams.CallbackStreamHandler"] = "jls/io/streams/CallbackStreamHandler.lua",
      ["jls.io.streams.ChunkedStreamHandler"] = "jls/io/streams/ChunkedStreamHandler.lua",
      ["jls.io.streams.DelayedStreamHandler"] = "jls/io/streams/DelayedStreamHandler.lua",
      ["jls.io.streams.FileStreamHandler"] = "jls/io/streams/FileStreamHandler.lua",
      ["jls.io.streams.LimitedStreamHandler"] = "jls/io/streams/LimitedStreamHandler.lua",
      ["jls.io.streams.PromiseStreamHandler"] = "jls/io/streams/PromiseStreamHandler.lua",
      ["jls.io.streams.PromisesStreamHandler"] = "jls/io/streams/PromisesStreamHandler.lua",
      ["jls.io.streams.RangeStreamHandler"] = "jls/io/streams/RangeStreamHandler.lua",
      ["jls.io.streams.StreamHandler"] = "jls/io/streams/StreamHandler.lua",
      ["jls.io.streams.WrappedStreamHandler"] = "jls/io/streams/WrappedStreamHandler.lua",
      ["jls.lang.Exception"] = "jls/lang/Exception.lua",
      ["jls.lang.ProcessBuilder"] = "jls/lang/ProcessBuilder.lua",
      ["jls.lang.ProcessHandle"] = "jls/lang/ProcessHandle.lua",
      ["jls.lang.ProcessHandle-"] = "jls/lang/ProcessHandle-.lua",
      ["jls.lang.ProcessHandle-linux"] = "jls/lang/ProcessHandle-linux.lua",
      ["jls.lang.ProcessHandle-luachild"] = "jls/lang/ProcessHandle-luachild.lua",
      ["jls.lang.ProcessHandle-luv"] = "jls/lang/ProcessHandle-luv.lua",
      ["jls.lang.ProcessHandle-win32"] = "jls/lang/ProcessHandle-win32.lua",
      ["jls.lang.ProcessHandleBase"] = "jls/lang/ProcessHandleBase.lua",
      ["jls.lang.Promise"] = "jls/lang/Promise.lua",
      ["jls.lang.StringBuffer"] = "jls/lang/StringBuffer.lua",
      ["jls.lang.Thread"] = "jls/lang/Thread.lua",
      ["jls.lang.Thread-llthreads"] = "jls/lang/Thread-llthreads.lua",
      ["jls.lang.Thread-luv"] = "jls/lang/Thread-luv.lua",
      ["jls.lang.ThreadBase"] = "jls/lang/ThreadBase.lua",
      ["jls.lang.class"] = "jls/lang/class.lua",
      ["jls.lang.event"] = "jls/lang/event.lua",
      ["jls.lang.event-"] = "jls/lang/event-.lua",
      ["jls.lang.event-luv"] = "jls/lang/event-luv.lua",
      ["jls.lang.formatCommandLine"] = "jls/lang/formatCommandLine.lua",
      ["jls.lang.loader"] = "jls/lang/loader.lua",
      ["jls.lang.logger"] = "jls/lang/logger.lua",
      ["jls.lang.loopWithTimeout"] = "jls/lang/loopWithTimeout.lua",
      ["jls.lang.luv_stream"] = "jls/lang/luv_stream.lua",
      ["jls.lang.protectedCall"] = "jls/lang/protectedCall.lua",
      ["jls.lang.protectedCallLog"] = "jls/lang/protectedCallLog.lua",
      ["jls.lang.runtime"] = "jls/lang/runtime.lua",
      ["jls.lang.setenv"] = "jls/lang/setenv.lua",
      ["jls.lang.sys"] = "jls/lang/sys.lua",
      ["jls.lang.sys-"] = "jls/lang/sys-.lua",
      ["jls.lang.sys-luv"] = "jls/lang/sys-luv.lua",
      ["jls.lang.sys-socket"] = "jls/lang/sys-socket.lua",
      ["jls.lang.system"] = "jls/lang/system.lua",
      ["jls.net.Selector-socket"] = "jls/net/Selector-socket.lua",
      ["jls.net.TcpClient"] = "jls/net/TcpClient.lua",
      ["jls.net.TcpServer"] = "jls/net/TcpServer.lua",
      ["jls.net.TcpSocket"] = "jls/net/TcpSocket.lua",
      ["jls.net.TcpSocket-luv"] = "jls/net/TcpSocket-luv.lua",
      ["jls.net.TcpSocket-socket"] = "jls/net/TcpSocket-socket.lua",
      ["jls.net.UdpSocket"] = "jls/net/UdpSocket.lua",
      ["jls.net.UdpSocket-luv"] = "jls/net/UdpSocket-luv.lua",
      ["jls.net.UdpSocket-socket"] = "jls/net/UdpSocket-socket.lua",
      ["jls.net.Url"] = "jls/net/Url.lua",
      ["jls.net.dns"] = "jls/net/dns.lua",
      ["jls.net.dns-luv"] = "jls/net/dns-luv.lua",
      ["jls.net.dns-socket"] = "jls/net/dns-socket.lua",
      ["jls.net.http.Attributes"] = "jls/net/http/Attributes.lua",
      ["jls.net.http.HeaderStreamHandler"] = "jls/net/http/HeaderStreamHandler.lua",
      ["jls.net.http.HttpClient"] = "jls/net/http/HttpClient.lua",
      ["jls.net.http.HttpContext"] = "jls/net/http/HttpContext.lua",
      ["jls.net.http.HttpExchange"] = "jls/net/http/HttpExchange.lua",
      ["jls.net.http.HttpFilter"] = "jls/net/http/HttpFilter.lua",
      ["jls.net.http.HttpHandler"] = "jls/net/http/HttpHandler.lua",
      ["jls.net.http.HttpHeaders"] = "jls/net/http/HttpHeaders.lua",
      ["jls.net.http.HttpMessage"] = "jls/net/http/HttpMessage.lua",
      ["jls.net.http.HttpRequest"] = "jls/net/http/HttpRequest.lua",
      ["jls.net.http.HttpResponse"] = "jls/net/http/HttpResponse.lua",
      ["jls.net.http.HttpServer"] = "jls/net/http/HttpServer.lua",
      ["jls.net.http.HttpSession"] = "jls/net/http/HttpSession.lua",
      ["jls.net.http.WebSocket"] = "jls/net/http/WebSocket.lua",
      ["jls.net.http.filter.BasicAuthenticationHttpFilter"] = "jls/net/http/filter/BasicAuthenticationHttpFilter.lua",
      ["jls.net.http.filter.LogHttpFilter"] = "jls/net/http/filter/LogHttpFilter.lua",
      ["jls.net.http.filter.PathHttpFilter"] = "jls/net/http/filter/PathHttpFilter.lua",
      ["jls.net.http.filter.SessionHttpFilter"] = "jls/net/http/filter/SessionHttpFilter.lua",
      ["jls.net.http.form"] = "jls/net/http/form.lua",
      ["jls.net.http.handler.FileHttpHandler"] = "jls/net/http/handler/FileHttpHandler.lua",
      ["jls.net.http.handler.ProxyHttpHandler"] = "jls/net/http/handler/ProxyHttpHandler.lua",
      ["jls.net.http.handler.RestHttpHandler"] = "jls/net/http/handler/RestHttpHandler.lua",
      ["jls.net.http.handler.TableHttpHandler"] = "jls/net/http/handler/TableHttpHandler.lua",
      ["jls.net.http.handler.WebDavHttpHandler"] = "jls/net/http/handler/WebDavHttpHandler.lua",
      ["jls.net.http.handler.ZipFileHttpHandler"] = "jls/net/http/handler/ZipFileHttpHandler.lua",
      ["jls.net.http.ws"] = "jls/net/http/ws.lua",
      ["jls.net.mqtt"] = "jls/net/mqtt.lua",
      ["jls.net.secure"] = "jls/net/secure.lua",
      ["jls.util.Channel"] = "jls/util/Channel.lua",
      ["jls.util.Codec"] = "jls/util/Codec.lua",
      ["jls.util.CoroutineScheduler"] = "jls/util/CoroutineScheduler.lua",
      ["jls.util.Date"] = "jls/util/Date.lua",
      ["jls.util.EventPublisher"] = "jls/util/EventPublisher.lua",
      ["jls.util.List"] = "jls/util/List.lua",
      ["jls.util.LocalDateTime"] = "jls/util/LocalDateTime.lua",
      ["jls.util.Map"] = "jls/util/Map.lua",
      ["jls.util.MessageDigest"] = "jls/util/MessageDigest.lua",
      ["jls.util.Scheduler"] = "jls/util/Scheduler.lua",
      ["jls.util.SerialWorker"] = "jls/util/SerialWorker.lua",
      ["jls.util.Struct"] = "jls/util/Struct.lua",
      ["jls.util.TableList"] = "jls/util/TableList.lua",
      ["jls.util.WebView"] = "jls/util/WebView.lua",
      ["jls.util.Worker"] = "jls/util/Worker.lua",
      ["jls.util.Worker-"] = "jls/util/Worker-.lua",
      ["jls.util.Worker-channel"] = "jls/util/Worker-channel.lua",
      ["jls.util.ast"] = "jls/util/ast.lua",
      ["jls.util.base64"] = "jls/util/base64.lua",
      ["jls.util.cd.base64"] = "jls/util/cd/base64.lua",
      ["jls.util.cd.cipher"] = "jls/util/cd/cipher.lua",
      ["jls.util.cd.deflate"] = "jls/util/cd/deflate.lua",
      ["jls.util.cd.gzip"] = "jls/util/cd/gzip.lua",
      ["jls.util.cd.hex"] = "jls/util/cd/hex.lua",
      ["jls.util.color"] = "jls/util/color.lua",
      ["jls.util.compat"] = "jls/util/compat.lua",
      ["jls.util.hex"] = "jls/util/hex.lua",
      ["jls.util.json"] = "jls/util/json.lua",
      ["jls.util.json-cjson"] = "jls/util/json-cjson.lua",
      ["jls.util.json-dkjson"] = "jls/util/json-dkjson.lua",
      ["jls.util.json-lunajson"] = "jls/util/json-lunajson.lua",
      ["jls.util.md.crc32"] = "jls/util/md/crc32.lua",
      ["jls.util.md.crc32-"] = "jls/util/md/crc32-.lua",
      ["jls.util.md.crc32-zlib"] = "jls/util/md/crc32-zlib.lua",
      ["jls.util.md.md5"] = "jls/util/md/md5.lua",
      ["jls.util.md.md5-"] = "jls/util/md/md5-.lua",
      ["jls.util.md.md5-openssl"] = "jls/util/md/md5-openssl.lua",
      ["jls.util.md.sha1"] = "jls/util/md/sha1.lua",
      ["jls.util.md.sha1-"] = "jls/util/md/sha1-.lua",
      ["jls.util.md.sha1-openssl"] = "jls/util/md/sha1-openssl.lua",
      ["jls.util.strings"] = "jls/util/strings.lua",
      ["jls.util.tables"] = "jls/util/tables.lua",
      ["jls.util.xml"] = "jls/util/xml.lua",
      ["jls.util.zip.Deflater"] = "jls/util/zip/Deflater.lua",
      ["jls.util.zip.Inflater"] = "jls/util/zip/Inflater.lua",
      ["jls.util.zip.ZipFile"] = "jls/util/zip/ZipFile.lua",
      ["jls.util.zip.gzip"] = "jls/util/zip/gzip.lua",
      ["jls.util.zip.tar"] = "jls/util/zip/tar.lua",
   },
   copy_directories = {
      "examples",
      "tests",
   }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.