{"id":13570803,"url":"https://github.com/fengari-lua/fengari","last_synced_at":"2025-05-13T00:06:22.375Z","repository":{"id":43642830,"uuid":"80605091","full_name":"fengari-lua/fengari","owner":"fengari-lua","description":"🌙 φεγγάρι - The Lua VM written in JS ES6 for Node and the browser","archived":false,"fork":false,"pushed_at":"2024-12-02T01:46:21.000Z","size":2971,"stargazers_count":1865,"open_issues_count":24,"forks_count":68,"subscribers_count":58,"default_branch":"master","last_synced_at":"2025-04-18T06:23:02.889Z","etag":null,"topics":["es6","fengari","javascript","lua","lua-vm","vm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fengari-lua.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS","contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":["daurnimator","giann"]}},"created_at":"2017-02-01T09:22:59.000Z","updated_at":"2025-04-17T08:40:11.000Z","dependencies_parsed_at":"2024-06-18T12:16:06.915Z","dependency_job_id":"e405d94e-ea51-4236-a9c6-5114c4cbaee7","html_url":"https://github.com/fengari-lua/fengari","commit_stats":{"total_commits":1274,"total_committers":8,"mean_commits":159.25,"dds":"0.38226059654631084","last_synced_commit":"eb2453c0c36f3802c8effeb65f36090de0c59a0e"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengari-lua%2Ffengari","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengari-lua%2Ffengari/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengari-lua%2Ffengari/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengari-lua%2Ffengari/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fengari-lua","download_url":"https://codeload.github.com/fengari-lua/fengari/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250452309,"owners_count":21432984,"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":["es6","fengari","javascript","lua","lua-vm","vm"],"created_at":"2024-08-01T14:00:55.118Z","updated_at":"2025-04-23T18:31:20.384Z","avatar_url":"https://github.com/fengari-lua.png","language":"JavaScript","readme":"[![Build Status](https://github.com/fengari-lua/fengari/actions/workflows/ci.yaml/badge.svg)](https://github.com/fengari-lua/fengari/actions/workflows/ci.yaml?query=event%3Apush)\n[![npm](https://img.shields.io/npm/v/fengari.svg)](https://npmjs.com/package/fengari)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![#fengari on libera.chat](https://img.shields.io/badge/chat-%23fengari-brightgreen)](https://web.libera.chat/?channels=#fengari)\n[![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/fengari-lua/fengari.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/fengari-lua/fengari/context:javascript)\n[![Total Alerts](https://img.shields.io/lgtm/alerts/g/fengari-lua/fengari.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/fengari-lua/fengari/alerts)\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/fengari-lua/fengari/raw/master/logo.png\" alt=\"Fengari\" width=\"304\" height=\"304\"\u003e\n\u003c/p\u003e\n\n\n# Fengari\n\n🌙 φεγγάρι - The Lua VM written in JS ES6 for Node and the browser\n\nThis repository contains the core fengari code (which is a port of the Lua C library) which includes parser, virtual machine and base libraries.\nHowever it is rare to use this repository directly.\n\n- To use fengari in a web browser as easily as you might use JavaScript, see [fengari-web](https://github.com/fengari-lua/fengari-web)\n- [fengari-interop](https://github.com/fengari-lua/fengari-interop) is a lua library that makes interoperating with JavaScript objects simple, it is already included in fengari-web.\n- For a clone of the `lua` command line tool, but running under node.js, see [fengari-node-cli](https://github.com/fengari-lua/fengari-node-cli)\n\n### The JS API\n\nOnce you've loaded fengari, you can use the JS API:\n\n```js\nconst luaconf  = fengari.luaconf;\nconst lua      = fengari.lua;\nconst lauxlib  = fengari.lauxlib;\nconst lualib   = fengari.lualib;\n\nconst L = lauxlib.luaL_newstate();\n\nlualib.luaL_openlibs(L);\n\nlua.lua_pushliteral(L, \"hello world!\");\n```\n\nThe JS API is exactly the same as the C API so `fengari.lua` exposes the same constants and functions as `lua.h`, `fengari.lauxlib` the same as `lauxlib.h` and `fengari.lualib` the same as `lualib.h`. If you're unfamiliar with the C API, you can take a look at [the manual](http://www.lua.org/manual/5.3/manual.html#4).\n\n\n## Semantics\n\nFengari implements Lua 5.3 semantics and will hopefully follow future Lua releases. If you find any noticeable difference between Fengari and Lua's behaviours, please [report it](https://github.com/fengari-lua/fengari/issues).\n\n### Strings\n\nLua strings are 8-bits clean and can embed `\\0`. Which means that invalid UTF-8/16 strings are valid Lua strings. Lua functions like `string.dump` even use strings as a way of storing binary data.\n\nTo address that issue, Fengari uses [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) objects containing the raw bytes to implement lua strings. To push a JS string on the stack you can use `lua_pushliteral` which will convert it to an array of bytes before pushing it. To get a Lua string on the stack as a JS string you can use `lua_tojsstring` which will attempt to convert it to a UTF-16 JS string. The latter won't give you what you expect if the Lua string is not a valid UTF-16 sequence. You can also convert strings with `luastring_of`, `to_luastring`, `to_jsstring` and `to_uristring`.\n\n\n### Integers\n\nThe JS number type is always a double, and hence cannot accurately represent integers with more than 53 bits. As such, we've taken the route of a rarely used define (`LUA_INT_TYPE=LUA_INT_LONG`) in the PUC-Rio sources, where floats are doubles, but integers are 32 bits.\n\n\n### `require` and `package.loadlib`\n\nIn the browser `require` and `package.loadlib` try to find a file by making synchronous XHR requests.\n\n`require` has been extended to allow searchers to yield.\n\n\n### _Missing_ features\n\n- `lua_gc`/`collectgarbage`: Fengari relies on the JS garbage collector and does not implement its own.\n- The following functions are only available in Node:\n    - The entire `io` lib\n    - `os.remove`\n    - `os.rename`\n    - `os.tmpname`\n    - `os.execute`\n- `debug.debug()` doesn't work from web workers due to lack of a method to get synchronous user input\n- [Weak tables](http://www.lua.org/manual/5.3/manual.html#2.5.2)\n- `__gc` metamethods\n\n\n### _Differences_\n\n- `package.jspath` instead of `package.cpath`\n- `LUA_JSPATH_DEFAULT` instead of `LUA_CPATH_DEFAULT` (and contains .js extensions rather than .so or .dll extensions)\n- `lua_tointegerx` and `lua_tonumberx` do not have out-parameters indicating conversion success. Instead, ``false`` is returned when conversion fails.\n- `luaL_execresult` takes an extra argument: an error object. The error object should have fields `status`, `signal` and `errno`.\n- `luaL_fileresult` takes an extra argument: an error object. The error object should have a field `errno`.\n\n\n### Configuring\n\nSome luaconf options can be chosen at library load time. Fengari looks for `process.env.FENGARICONF` and if it exists, parses it as a JSON string.\n\n\n## Extensions\n\n### `dv = lua_todataview(L, idx)`\n\nEquivalent to `lua_tolstring` but returns a [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) instead of a string.\n\n\n### `lua_pushjsfunction(L, func)`\n\nAlias for `lua_pushcfunction`.\n\n\n### `lua_pushjsclosure(L, func, n)`\n\nAlias for `lua_pushcclosure`.\n\n\n### `lua_atnativeerror(L, func)`\n\nSets a function to be called if a native JavaScript error is thrown across a lua pcall.\nThe function will be run as if it were a message handler (see https://www.lua.org/manual/5.3/manual.html#2.3).\nThe current message handler will be run after the native error handler returns.\n\n\n### `b = lua_isproxy(p, L)`\n\nReturns a boolean `b` indicating whether `p` is a proxy (See `lua_toproxy`).\nIf `L` is non-null, only returns `true` if `p` belongs to the same global state.\n\n\n### `p = lua_toproxy(L, idx)`\n\nReturns a JavaScript object `p` that holds a reference to the lua value at the stack index `idx`.\nThis object can be called with a lua_State to push the value onto that state's stack.\n\nThis example would be an inefficient way to write `lua_pushvalue(L, 1)`:\n\n```js\nvar p = lua_toproxy(L, 1);\np(L);\n```\n\n\n### `fengari` library\n\nA library containing metadata about the fengari release.\n\n  - `AUTHORS`\n  - `COPYRIGHT`\n  - `RELEASE`\n  - `VERSION`\n  - `VERSION_MAJOR`\n  - `VERSION_MINOR`\n  - `VERSION_NUM`\n  - `VERSION_RELEASE`\n\nThis library is automatically loaded by `luaL_openlibs` into the global `\"fengari\"`.\n\n\n## NYI\n\n- `io.input()`: partially implemented\n- `io.lines()`\n- `io.open()`\n- `io.output()`: partially implemented\n- `io.popen()`\n- `io.read()`\n- `io.tmpfile()`\n- `file:lines()`\n- `file:read()`\n- `file:setvbuf()`\n- `file:__gc()`\n\n\n## References\n\n- [Source code for Lua 5.3](lua.org/source/5.3/)\n- [Lua 5.2 Bytecode and Virtual Machine](http://files.catwell.info/misc/mirror/lua-5.2-bytecode-vm-dirk-laurie/lua52vm.html)\n- [Lua 5.3 Bytecode Reference](http://the-ravi-programming-language.readthedocs.io/en/latest/lua_bytecode_reference.html)\n- [A No-Frills Introduction to Lua 5.1 VM Instructions](http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf)\n","funding_links":["https://github.com/sponsors/daurnimator","https://github.com/sponsors/giann"],"categories":["JavaScript","Packages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffengari-lua%2Ffengari","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffengari-lua%2Ffengari","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffengari-lua%2Ffengari/lists"}