{"id":24584737,"url":"https://github.com/ysugimoto/webassembly-lua","last_synced_at":"2025-04-28T11:13:12.523Z","repository":{"id":41112411,"uuid":"152550850","full_name":"ysugimoto/webassembly-lua","owner":"ysugimoto","description":"Write and compile WebAssembly code with Lua","archived":false,"fork":false,"pushed_at":"2022-06-28T13:36:57.000Z","size":36,"stargazers_count":130,"open_issues_count":1,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-28T11:12:57.561Z","etag":null,"topics":["lua","webassembly"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/ysugimoto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-11T07:38:14.000Z","updated_at":"2025-04-22T12:55:14.000Z","dependencies_parsed_at":"2022-09-09T06:20:56.315Z","dependency_job_id":null,"html_url":"https://github.com/ysugimoto/webassembly-lua","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/ysugimoto%2Fwebassembly-lua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysugimoto%2Fwebassembly-lua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysugimoto%2Fwebassembly-lua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysugimoto%2Fwebassembly-lua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysugimoto","download_url":"https://codeload.github.com/ysugimoto/webassembly-lua/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251302782,"owners_count":21567601,"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":["lua","webassembly"],"created_at":"2025-01-24T04:57:20.713Z","updated_at":"2025-04-28T11:13:12.482Z","avatar_url":"https://github.com/ysugimoto.png","language":"Python","readme":"# webassembly-lua\n\nWrite and compile as WebAssembly program by lua script.\n\n**Note: this project is still under development. We have to do more improvement**\n\n## Requirements\n\n- [emscripten](https://github.com/kripken/emscripten)\n- [lua](https://www.lua.org/) (prefer to use latest version)\n- Python 3.6.5+\n\nTo avoid to polute your environment, we *strongly* prefer to use prebuilt docker image on [docker hub](https://hub.docker.com/r/ysugimoto/webassembly-lua/).\n\n## How to use\n\n### Write lua script\n\nHere is example `Hello World` script:\n\n```lua\nfunction hello_world()\n  return 'Hello, WebAssembly Lua!'\nend\n```\n\nMake sure the function declares as *global* in order to access from C program.\nAnd, also you can specify some function arguments like:\n\n```lua\nfunction hello_something(something):\n  return ('Hello, %s!'):format(something)\nend\n```\n\nThen, you need to remember what `type` of argument should be supplied and what `type` of value will return (supports `string` or `int` for now).\n\n### Write definitions in `definition.yml`\n\nThe `definition.yml` is configuration for generate / compile WebAssembly binary. See following:\n\n```yaml\ndependencies:\n  - luaposix\n\nfunctions:\n  hello_something:\n    return : string\n    args:\n      - string\n\nentry_file: hello_world.lua\noutput_file: hello_world.html\n```\n\nDescribes each fields:\n\n| Field                  | Type    | Default  | description                                                                    |\n|:-----------------------|:-------:|:--------:|:-------------------------------------------------------------------------------|\n| dependencies           | array   | -        | program dependencies. the list of modules will be installed via `luarocks`.    |\n| functions              | object  | -        | Function definitions. The key is function name which will be exported on WASM. |\n| functions[name].return | string  | -        | Define function return type.                                                   |\n| functions[name].args   | array   | -        | Defined function argument type list.                                           |\n| entry_file             | strring | main.lua | the file name of program entry.                                                |\n| output_file            | strring | -        | the file name of output files.                                                 |\n\n### Compile as WebAssembly program\n\nOn docker image, the image has `emcc-lua` command:\n\n```shell\n$ docker pull ysugimoto/webassembly-lua\n$ docker run --rm -v $PWD:/src ysugimoto/webassembly-lua emcc-lua\n```\n\nThe `emcc-lua` finds `definition.yml` in current working directory (in this case, `$PWD`) and start to build.\nAfter built successfully, you can see a `hello_world.[html,js,wasm]` in your directory. The output file is named by `entry_file` in definition.yml.\n\n### Run WebAssembly program\n\nOpen created or write HTML to run compiled WebAssembly program like:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eWebAssembly Lua\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cscript src=\"./hello_world.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n    Module.onRuntimeInitialized = () =\u003e {\n      // call your function through the Module.cwrap()\n      const helloSomething = Module.cwrap('hello_something', 'string', ['string']);\n      console.log(helloSomething('WebAssembly Lua'));\n    };\n    \u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nAnd run local server in your favorite way (e.g python -m http.server) and access to `http://localhost:8000/hello_world.html` (port may need), then you can see `Hello, WebAssembly Lua!` message in your browser console.\n\n## Features\n\n- [x] Compile single lua script to WebAssembly binary\n- [x] Support for return type of string and int\n- [x] Support to call function with any arguments\n- [x] Enable to bundle some libraries (e.g. hosted on luarocks, or Independent C libraries)\n\n## TODOs\n\n- [x] Support to require other lua modules which you defined as other file, installed via luarocks\n- [x] Support to apply function arguments as detected types\n- [x] Works with more complicated script. Now we can work on simple script.\n- [ ] Support some structured return type which can use in JavaScript (Array, Object -- especially JSON --)\n- [ ] Try to compile various libraries (Now we tried to bundle `luaposix`, it's fine to work)\n\n## Author\n\nYoshiaki Sugimoto\n\n## License\n\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysugimoto%2Fwebassembly-lua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysugimoto%2Fwebassembly-lua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysugimoto%2Fwebassembly-lua/lists"}