# glua

> Full-featured Lua VM for nodejs and the browser. Based on github.com/yuin/gopher-lua.

Latest version **1.0.2** (published 2019-02-25) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-02-25 |
| First published | 2017-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 140 |
| Author | Giovanni T. Parra |
| Maintainers | fiatjaf |
| Keywords | lua vm compiler gopher-lua gopherjs |

## Links

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

## 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

- 1.0.2 (latest) — 2019-02-25
- 1.0.1 — 2019-02-25
- 0.4.5 — 2017-05-09
- 0.3.4 — 2017-05-08
- 0.2.3 — 2017-05-05
- 0.1.2 — 2017-05-04
- 0.0.1 — 2017-04-11

## README

## glua [![npm badge](https://img.shields.io/npm/v/glua.svg)](https://www.npmjs.com/package/glua)

`glua` is what happens when you compile https://github.com/J-J-J/goluajit, a Lua VM written in Go (based on https://github.com/yuin/gopher-lua), to Javascript. It works right now and you can use it for most awesomeness. You don't have to know Go or even click on the link above, just use this library in your favorite JS environment.

### example:

```js
const glua = require('glua')

glua.run(`
  print(12, 'lala', true)
`) // will print these values

var result

glua.runWithGlobals({
  diff: function (a, b) {
    return Math.abs(Math.abs(b) - Math.abs(a))
  },
  saveResult: function (value) {
    result = value
  }
}, `
  local a = 23
  local b = 74
  local difference = diff(a, b)
  saveResult(difference)
`)

console.log('the result is: ', result)

glua.runWithModules({
  fooprinter: `
local fooprinter = {}

function fooprinter.print (foo)
  print('foo value is: ', foo)
end

return fooprinter
  `
}, {
  foo: 264857
}, `
local fooprinter = require('fooprinter')
print('printing foo...')
fooprinter.print(foo)
`)
```

### try it now

Visit https://raw.githack.com/fiatjaf/glua/master/try.html and use your console.

## how do I

1. Return multiple values from a JavaScript function?

  Return the special object `{_glua_multi: []}` with an array of the multiple values you want your function to return.

2. Get values out from the Lua environment?

  Call `.runWithGlobals` passing a function that takes the parameters from Lua and saves them to a JavaScript variable. It works.

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