# wasm2lua

> A tool to convert WASM into Lua

Latest version **0.8.11** (published 2021-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install wasm2lua
pnpm add wasm2lua
yarn add wasm2lua
bun add wasm2lua
```

Provides the commands `wasm2lua`, `lua-webidl`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.11 |
| Published | 2021-12-12 |
| First published | 2019-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 12.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 220 |
| Author | swadical |
| Maintainers | swadicalrag |
| Keywords | wasm, lua, compiler, transpiler, wasi, luajit, webassembly |

## Links

- npm: https://www.npmjs.com/package/wasm2lua
- Repository: https://github.com/SwadicalRag/wasm2lua
- Homepage: https://github.com/SwadicalRag/wasm2lua#readme
- Issues: https://github.com/SwadicalRag/wasm2lua/issues
- npm.io page: https://npm.io/package/wasm2lua

## Dependencies (6)

- [colors](https://npm.io/package/colors.md) ^1.3.3
- [luamin](https://npm.io/package/luamin.md) ^1.0.4
- [webidl2](https://npm.io/package/webidl2.md) ^21.1.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.0.1
- [commander](https://npm.io/package/commander.md) ^2.20.0
- [@webassemblyjs/wasm-parser](https://npm.io/package/@webassemblyjs/wasm-parser.md) ^1.8.5

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.8.11 (latest) — 2021-12-12
- 0.8.10 — 2021-12-12
- 0.8.9 — 2021-12-12
- 0.8.8 — 2021-11-19
- 0.8.7 — 2021-11-19
- 0.8.6 — 2021-11-19
- 0.8.4 — 2019-09-08
- 0.8.3 — 2019-06-09
- 0.8.0 — 2019-06-09
- 0.7.3 — 2019-06-09
- 0.7.2 — 2019-06-09
- 0.7.1 — 2019-06-09
- 0.7.0 — 2019-06-08
- 0.6.3 — 2019-06-08
- 0.6.2 — 2019-06-08
- … 17 more at https://npm.io/package/wasm2lua/versions

## README

# 🎉 wasm2lua 🎊

![](https://forthebadge.com/images/badges/powered-by-electricity.svg) ![](https://forthebadge.com/images/badges/made-with-crayons.svg)

[![travis ci](https://travis-ci.com/SwadicalRag/wasm2lua.svg?branch=master)](https://travis-ci.com/SwadicalRag/wasm2lua)

Have YOU ever wanted to run C++/C/Rust/javascript/banana/etc. on Lua without using native modules?

GOOD NEWS, fam: `wasm2lua` can compile WebAssembly modules to pure Lua (or with FFI LuaJIT for extra speed). This means that anything that can be compiled to WASM can be compiled to Lua! Long Live John Lua!

## Notes

 - The generated code is heavily dependent upon the LuaJIT bit library
 - Some of `@webassemblyjs`'s libraries are monkey patched at runtime
 - `luamin` is monkey patched at runtime
 - The WASI API is still under heavy development
 - Emscripten is NOT supported out of the box. You will need to compile things via the WASI ecosystem.

# Usage

`wasm2lua <in.wasm> <out.lua>`

`lua-webidl <in.idl> <out.cpp> --cpp`

(Run those commands with `--help` for other options)

See `HOWTO-BINDINGS.md` in this repository for reference on how to use the WebIDL binder.

## Installation

`npm i -g wasm2lua`

# Projects that use `wasm2lua`

 - [bullet3-lua](https://github.com/SwadicalRag/bullet3-lua) ([Releases](https://github.com/SwadicalRag/bullet3-lua/releases/), [Demo](https://github.com/SwadicalRag/bullet3-lua/blob/master/test.lua)), built with CMake
 - [brotli-lua](https://github.com/SwadicalRag/brotli-lua) ([Releases](https://github.com/SwadicalRag/brotli-lua/releases/), [Demo](https://github.com/SwadicalRag/brotli-lua/blob/master/test.lua)), built with CMake
 - [tiny-regex-lua](https://github.com/SwadicalRag/tiny-regex-lua) ([Demo](https://github.com/SwadicalRag/tiny-regex-lua/blob/master/test.lua)), built with a Makefile

### BONUS: duktape via wasm2lua

```c
int main(int argc, char *argv[]) {
	duk_context *ctx = duk_create_heap_default();

	(void) argc; (void) argv;  /* suppress warning */

	duk_push_c_function(ctx, native_print, DUK_VARARGS);
	duk_put_global_string(ctx, "print");
	duk_push_c_function(ctx, native_adder, DUK_VARARGS);
	duk_put_global_string(ctx, "adder");

	duk_eval_string(ctx, "print('Hello world!');");

	duk_eval_string(ctx, "print('2+3=' + adder(2, 3));");
	duk_pop(ctx);  /* pop eval result */

	duk_destroy_heap(ctx);

	return 0;
}

```

![duktape demo](resources/img/duktape.png)

---
_Source: https://npm.io/package/wasm2lua · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
