{"id":17483749,"url":"https://github.com/creationix/moonslice-luv","last_synced_at":"2025-04-10T02:43:40.371Z","repository":{"id":4993839,"uuid":"6151978","full_name":"creationix/moonslice-luv","owner":"creationix","description":"A port of moonslice running on top of luv and lhttp_parser","archived":false,"fork":false,"pushed_at":"2014-05-02T20:52:37.000Z","size":502,"stargazers_count":39,"open_issues_count":1,"forks_count":4,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-19T03:27:10.319Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creationix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-10T04:12:13.000Z","updated_at":"2023-10-14T08:39:49.000Z","dependencies_parsed_at":"2022-07-09T09:00:42.060Z","dependency_job_id":null,"html_url":"https://github.com/creationix/moonslice-luv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fmoonslice-luv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fmoonslice-luv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fmoonslice-luv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fmoonslice-luv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creationix","download_url":"https://codeload.github.com/creationix/moonslice-luv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248145358,"owners_count":21055112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-19T00:27:51.354Z","updated_at":"2025-04-10T02:43:40.347Z","avatar_url":"https://github.com/creationix.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"Moonslice is a collection of interfaces and lua libraries.\n\nIt's a mix of the code and technology from the luvit project mixed with some\nnew experimental APIs that are designed to make it more lua friendly and easier\nto code.\n\nTwo external dependencies are `luv` and `lhttp_parser`.  The first is a new set\nof lua - libuv bindings designed to be standalone, minimal and fast.  The latter\nis the http_parser bindings used in luvit, but packaged as a standalone project.\n\nIncluded in this directory is a `Makefile` that pulls in the gitsubmodules and\nbuilds the two libraries.  The respective libraries that use them have symlinks\nin place already.\n\n# Continuable\n\nThis is a collection of libraries that implement the continuable interface.\n\nIn short, the continuable interface is like node.js style callbacks except the\nfunction that accepts the callback is returned from the initial function call\nas a continuable closure.\n\n```lua\nfs.readFile(\"/path/to/file.txt\")(function (err, contents)\n  ...\nend)\n```\n\n# Continuable.stream\n\nThis library contains the stream implementation.  It's a simple queue where\nwrites to one end come out in reads to the other end.  Built-in is backpressure\nand controlled buffering via low-water and high-water marks for full proper\nflow-control.\n\nThe streams have only `.read()` and `.write()` continuable style functions.\nThey are mobile and can be moved around at will as seen in this example for\ncreating a duplex pipe with a stream at each end.\n\n```lua\nlocal function newPipe()\n  -- Create two streams\n  local a, b = newStream(), newStream()\n  -- Cross their write functions\n  a.write, b.write = b.write, a.write\n  -- Return them as two duplex streams that are the two ends of the pipe\n  return a, b\nend\n```\n\n# Web\n\nThis library is a new web interface.  Web consumes a raw http stream (usually\nover TCP, but any stream will do) and a web `app`.  It parses HTTP requests on\nthe stream and calls the app function.  When the app function responds, it\nwrites the corresponding HTTP data to the socket.\n\n```lua\nlocal function app(req, res)\n  res(200, {\n    [\"Content-Type\"] = \"text/plain\"\n  }, \"Hello World\\n\")\nend\n```\n\n## Web.autoheaders\n\nThis middleware wraps around any web app and adds in all sorts of useful spec\nadherence.  It does useful things like auto Content-Length header.  Also it can\ndo chunked encoding on the body stream if it's unable to calculate the length.\n\n```lua\n-- Just wrap your app in autoheaders to get a new app\napp = autoheaders(app)\n```\n\n## Web.log\n\nA very simple middleware to log HTTP requests.\n\n```lua\n-- Just wrap your app in autoheaders to get a new app\napp = log(app)\n```\n\n## Web.websocket\n\n**TODO**: Finish implementing this API\n\nA sample websocket implementation to prove that web is capable of handling HTTP\nupgrades.\n\n```lua\nlocal app = function (req, res)\n  if not req.upgrade then\n    res(400, {}, \"Websocket only\\n\")\n  end\n  local socket = websocket.upgrade(req)\n  repeat\n    local message, head = await(socket.read())\n    p({\n      message=message,\n      opcode=head.opcode\n    })\n    socket.write(\"Hello \" .. message)()\n  until not message\nend\n```\n\n## Web.gzip\n\n**TODO**: Implement this\n\nA middleware to gzip body streams.  This is just an example of how this would be\ndone.  I think I'll implement it using FFI calls to zlib.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreationix%2Fmoonslice-luv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreationix%2Fmoonslice-luv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreationix%2Fmoonslice-luv/lists"}