{"id":13580193,"url":"https://github.com/luvit/luvi","last_synced_at":"2025-04-06T02:31:08.992Z","repository":{"id":20528459,"uuid":"23807586","full_name":"luvit/luvi","owner":"luvit","description":"A project in-between luv and luvit.","archived":false,"fork":false,"pushed_at":"2025-03-03T14:24:52.000Z","size":3599,"stargazers_count":319,"open_issues_count":6,"forks_count":64,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-03-03T15:33:09.124Z","etag":null,"topics":["hacktoberfest","libuv","lua","luajit","luvit"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luvit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-08T20:44:21.000Z","updated_at":"2025-03-03T14:24:59.000Z","dependencies_parsed_at":"2024-01-06T08:32:20.279Z","dependency_job_id":"bc94b862-a4d6-4468-9921-616a901c700e","html_url":"https://github.com/luvit/luvi","commit_stats":null,"previous_names":[],"tags_count":80,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluvi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluvi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluvi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluvi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luvit","download_url":"https://codeload.github.com/luvit/luvi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247425844,"owners_count":20937027,"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":["hacktoberfest","libuv","lua","luajit","luvit"],"created_at":"2024-08-01T15:01:48.548Z","updated_at":"2025-04-06T02:31:08.548Z","avatar_url":"https://github.com/luvit.png","language":"C","readme":"# luvi\n\n[![Build Status](https://github.com/luvit/luvi/actions/workflows/ci.yml/badge.svg)](https://github.com/luvit/luvi/actions/workflows/ci.yml)\n\nA project in-between [luv][] and [luvit][].\n\nThe goal of this is to make building [luvit][] and [derivatives][] much easier.\n\n## Workflow\n\nLuvi has a somewhat unique, but very easy workflow for creating self-contained binaries on systems that don't have a\ncompiler.\n\n```sh\n# Make a folder\ngit init myapp\n# Write the app\nvim myapp/main.lua\n# Run the app\nluvi myapp\n# Build the binary when done\nluvi myapp -o mybinary\n# Build the binary with compiled Lua bytecode\nluvi myapp -o mybinary --compile\n# Build the binary with compiled and stripped Lua bytecode\nluvi myapp -o mybinary --strip\n# Run the new self-contained binary\n./mybinary\n# Deploy / Publish / Profit!\n```\n\n## Main API\n\nYour `main.lua` is run in either a mostly stock [lua][] or [luajit][] environment with a few extra things added. Luajit\nis built with `LUAJIT_ENABLE_LUA52COMPAT` features turned on, and all luajit [extensions][] are available. Lua is built\nwith the `bit` library included, for parity with luajit.\n\n### Libuv is baked in\n\nThe \"uv\" module contains bindings to [libuv][] as defined in the [luv][] project. Simply `require(\"uv\")` to access it.\nThe \"uv\" module is also provided under the name \"luv\" for parity with luarocks, so `require(\"luv\")` will also work.\n\nUse this for file I/O, network I/O, timers, or various interfaces with the operating system. This lets you write fast\nnon-blocking network servers or frameworks. The APIs in [luv][] mirror what's in [libuv][] allowing you to add\nwhatever API sugar you want on top be it callbacks, coroutines, or whatever.\n\nJust be sure to call `uv.run()` and the end of your script to start the event loop if you want to actually wait for any\nevents to happen.\n\n[extensions]: http://luajit.org/extensions.html\n[lua]: https://www.lua.org/\n[luajit]: https://luajit.org/\n[libuv]: https://github.com/joyent/libuv\n[luv]: https://github.com/luvit/luv\n[luvit]: https://luvit.io/\n[derivatives]: http://virgoagent.com/\n\n```lua\nlocal uv = require('uv')\n\nlocal function setTimeout(timeout, callback)\n    local timer = uv.new_timer()\n    local function ontimeout()\n        print(\"ontimeout\", self)\n        uv.timer_stop(timer)\n        uv.close(timer)\n        callback(self)\n    end\n    uv.timer_start(timer, timeout, 0, ontimeout)\n    return timer\nend\n\nsetTimeout(1000, function ()\n    print(\"This happens later\")\nend)\n\nprint(\"This happens first\")\n\n-- This blocks till the timer is done\nuv.run()\n```\n\n### Integration with C's main function\n\nThe raw `argc` and `argv` from C side is exposed as a **zero** indexed lua table of strings at `args`. The `0`-th\nelement is generally the name of the binary that was executed.\n\n```lua\nprint(\"Your arguments were\")\nfor i = 0, #args do\n    print(i, args[i])\nend\n```\n\nThe \"env\" module provides read/write access to your local environment variables via `env.keys`, `env.get`, `env.put`,\n`env.set`, and `env.unset`.\n\nIf you return an integer from `main.lua` it will be your program's exit code.\n\n### Bundle I/O\n\nIf you're running from a unzipped folder on disk or a zipped bundle appended to the binary, the I/O to read from this\nis the same. This is exposed as the `bundle` property in the \"luvi\" module.\n\n```lua\nlocal bundle = require(\"luvi\").bundle\nlocal files = bundle.readdir(\"\")\n```\n\n#### bundle.stat(path)\n\nLoad metadata about a file in the bundle. This includes `type` (\"file\" or \"directory\"), `mtime` (in ms since epoch),\nand `size` (in bytes).\n\nIf the file doesn't exist, it returns `nil`.\n\n#### bundle.readdir(path)\n\nRead a directory. Returns a list of filenames in the directory.\n\nIf the directory doesn't exist, it return `nil`.\n\n#### bundle.readfile(path)\n\nRead the contents of a file. Returns a string if the file exists and `nil` if it doesn't.\n\n## Building from Source\n\nWe maintain several [binary releases of luvi](https://github.com/luvit/luvi/releases) to ease bootstrapping of lit and\nluvit apps.\n\nThe following platforms are actively supported and tested by the CI system:\n\n- Windows \u003e= 10 (x86_64 / i386)\n- Linux \u003e= 3.10, glibc \u003e= 2.17 OR musl \u003e= 1.0 (x86_64 / i386 / aarch64)\n  - Debian 8+\n  - Ubuntu 13.10+\n  - Fedora 19+\n- OSX 13+ (x86_64 / aarch64)\n\nThe following platforms are supported but not actively tested by the CI system:\n\n- Windows \u003e= 8 (x86_64 / i386)\n- OSX 11+ (x86_64 / aarch64)\n- FreeBSD 12+\n\nPlatform support is primarily based on libuv's [platform support](https://github.com/libuv/libuv/blob/v1.x/SUPPORTED_PLATFORMS.md).\n\nArchitecture support is primarily based on luajit's [platform support](https://luajit.org/luajit.html).\n\n### Build Dependencies\n\nIf you want to not wait for pre-built binaries and dive right in, building is based on CMake and is pretty simple.\n\n- Git\n- CMake\n- A C Compiler (Visual Studio 15+ OR MinGW on Windows)\n- Perl (required for OpenSSL)\n- NASM (required for OpenSSL ASM optimizations on Windows)\n\nFirst clone this repo recursively.\n\n```sh\ngit clone --recursive https://github.com/luvit/luvi.git\n```\n\n\u003e [!IMPORTANT]\n\u003e If you're on windows, for all following steps you will need to be in a [Visual Studio Command Prompt](https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022).\n\u003e\n\u003e You will need to replace `make` with `nmake` in the following commands.\n\nThen enter the directory and run the makefile inside it, which will assume you have all the dependencies installed,\nprimarily CMake.\n\nPrior to building luvi you must configure the version of luvi that you want to build. Currently there are two versions:\n\n- `tiny`: only the necessities, includes only Lua, Libuv, miniz, and minimal luvi modules.\n- `regular`: the normal luvit experience, includes OpenSSL, LPeg, and lrexlib.\n\n```sh\ncd luvi\nmake regular\nmake\nmake test\n```\n\nWhen that's done you should have a luvi binary in `build/luvi`.\n\n```sh\n$ ls -lh build/luvi\n-rwxr-xr-x 1 tim tim 948K Nov 20 16:39 build/luvi\n```\n\n## Usage\n\nRun it to see usage information:\n\n```sh\n$ luvi -h\n\nUsage: luvi bundle+ [options] [-- extra args]\n\n  bundle            Path to directory or zip file containing bundle source.\n                    `bundle` can be specified multiple times to layer bundles\n                    on top of each other.\n  --version         Show luvi version and compiled in options.\n  --output target   Build a luvi app by zipping the bundle and inserting luvi.\n  --main path       Specify a custom main bundle path (normally main.lua)\n  --compile         Compile Lua code into bytecode before bundling.\n  --strip           Compile Lua code and strip debug info.\n  --force           Ignore errors when compiling Lua code.\n  --help            Show this help file.\n  --                All args after this go to the luvi app itself.\n\nExamples:\n\n  # Run an app from disk, but pass in arguments\n  luvi path/to/app -- app args\n\n  # Run from a app zip\n  luvi path/to/app.zip\n\n  # Run an app that layers on top of luvit\n  luvi path/to/app path/to/luvit\n\n  # Bundle an app with luvi to create standalone\n  luvi path/to/app -o target\n  ./target some args\n\n  # Run unit tests for a luvi app using custom main\n  luvi path/to/app -m tests/run.lua\n```\n\nYou can run the sample repl app by doing:\n\n```sh\nbuild/luvi samples/repl.app\n```\n\nOt the test suite with:\n\n```sh\nbuild/luvi samples/test.app\n```\n\n## CMake Flags\n\nYou can use the predefined makefile targets if you want or use cmake directly\nfor more control.\n\n```text\nWithOpenSSL (Default: OFF)      - Enable OpenSSL Support\nWithOpenSSLASM (Default: OFF)   - Enable OpenSSL Assembly Optimizations\nWithSharedOpenSSL (Default: ON) - Use System OpenSSL Library\n                                  Otherwise use static library\n\nOPENSSL_ROOT_DIR                - Override the OpenSSL Root Directory\nOPENSSL_INCLUDE_DIR             - Override the OpenSSL Include Directory\nOPENSSL_LIBRARIES               - Override the OpenSSL Library Path\n```\n\nExample (Static OpenSSL):\n\n```sh\ncmake \\\n    -DWithOpenSSL=ON \\\n    -DWithSharedOpenSSL=OFF \\\n    ..\n```\n\nExample (Shared OpenSSL):\n\n```sh\ncmake \\\n    -DWithSharedOpenSSL=ON \\\n    -DWithOpenSSL=ON \\\n    -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \\\n    -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include \\\n    -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib \\\n    ..\n```\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluvit%2Fluvi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluvit%2Fluvi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluvit%2Fluvi/lists"}