{"id":16299005,"url":"https://github.com/teoxoy/lua-in-js","last_synced_at":"2025-04-10T04:57:51.954Z","repository":{"id":94652476,"uuid":"127682990","full_name":"teoxoy/lua-in-js","owner":"teoxoy","description":"A Lua to JS transpiler / runtime","archived":false,"fork":false,"pushed_at":"2024-07-13T08:51:34.000Z","size":378,"stargazers_count":80,"open_issues_count":2,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-11T20:46:21.089Z","etag":null,"topics":["javascript","lua","runtime","transpiler"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/teoxoy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2018-04-02T00:34:56.000Z","updated_at":"2024-09-29T22:41:44.000Z","dependencies_parsed_at":"2023-10-14T23:07:51.010Z","dependency_job_id":"3cbbea75-59f9-4e0c-828a-2b3a087e57e2","html_url":"https://github.com/teoxoy/lua-in-js","commit_stats":{"total_commits":21,"total_committers":2,"mean_commits":10.5,"dds":0.04761904761904767,"last_synced_commit":"f083952b9f965ea8559a16efb2dd1e0b7af67b77"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teoxoy%2Flua-in-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teoxoy%2Flua-in-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teoxoy%2Flua-in-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teoxoy%2Flua-in-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teoxoy","download_url":"https://codeload.github.com/teoxoy/lua-in-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161264,"owners_count":21057554,"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":["javascript","lua","runtime","transpiler"],"created_at":"2024-10-10T20:46:15.431Z","updated_at":"2025-04-10T04:57:51.931Z","avatar_url":"https://github.com/teoxoy.png","language":"TypeScript","readme":"# lua-in-js\n\n[![npm](https://img.shields.io/npm/v/lua-in-js.svg?style=flat-square)](https://www.npmjs.com/package/lua-in-js)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg?style=flat-square)](./CONTRIBUTING.md)\n[![GitHub](https://img.shields.io/github/license/teoxoy/lua-in-js.svg?style=flat-square\u0026color=blue)](./LICENSE)\n\u0026nbsp;\u0026nbsp;_Badges are clickable!_\n\nA Lua to JS transpiler/runtime. This library is a rewrite of [Starlight](https://github.com/paulcuth/starlight) with a lot of improvements.\n\n## Install\n\n```\nnpm i lua-in-js\n```\n\n## API\n\n### Import\n\n```js\nimport * as luainjs from 'lua-in-js'\n```\n\n```js\nconst luainjs = require('lua-in-js')\n```\n\n### Create the lua environment\n\nLua environments are isolated from each other (they got different global scopes)\n\n```js\nconst luaEnv = luainjs.createEnv()\n```\n\nA config object can be passed in for extra functionality\n\n```js\nconst luaEnv = luainjs.createEnv({\n    LUA_PATH,   // default value of package.path\n    fileExists, // function that takes in a path and returns a boolean\n    loadFile,   // function that takes in a path and returns the content of a file\n    stdin,      // string representing the standard input\n    stdout,     // function representing the standard output\n    osExit      // function called by os.exit\n})\n```\n\n### Execute a script or file\n\n```js\nconst luaScript = luaEnv.parse('print(\\'Hello world!\\')')\nconst returnValue = luaScript.exec()\n```\n\n```js\nconst luaScript = luaEnv.parseFile('somefile.lua')\nconst returnValue = luaScript.exec()\n```\n\n`parseFile` uses `config.fileExists` and `config.loadFile`\n\n### Create a global library\n\nCreating a global library allows you write APIs that you can use in the Lua environment.\n\n```js\nfunction helloBuilder(name) {\n    const NAME = luainjs.utils.coerceArgToString(name, 'sayHi', 1)\n    return `Hello ${NAME}!`\n}\n\nconst myLib = new luainjs.Table({ helloBuilder })\nluaEnv.loadLib('myLib', myLib)\n\nconst helloStr = luaEnv.parse(`return myLib.helloBuilder('John')`).exec()\nconsole.log(helloStr)\n```\n\nCheck out the [math lib](./src/lib/math.ts) for a more extensive example.\n\n## Example\n\nCheck out the [test runner](./tests/test.js) for a concrete example.\n\n## Missing functionality\n\n - coroutine library\n - debug library\n - utf8 library\n - io library\n - package.cpath\n - package.loadlib\n - string.dump\n - string.pack\n - string.packsize\n - string.unpack\n - os.clock\n - os.execute\n - os.getenv\n - os.remove\n - os.rename\n - os.tmpname\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteoxoy%2Flua-in-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteoxoy%2Flua-in-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteoxoy%2Flua-in-js/lists"}