You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Teoxoy 8a4691f1a1
2.0.1
6 years ago
.vscode typescript rewrite (v2) 6 years ago
src typescript rewrite (v2) 6 years ago
tests typescript rewrite (v2) 6 years ago
.eslint.base.yml typescript rewrite (v2) 6 years ago
.eslint.import.yml typescript rewrite (v2) 6 years ago
.eslint.typescript.yml typescript rewrite (v2) 6 years ago
.eslintrc.js typescript rewrite (v2) 6 years ago
.gitignore typescript rewrite (v2) 6 years ago
.prettierrc.js typescript rewrite (v2) 6 years ago
CONTRIBUTING.md typescript rewrite (v2) 6 years ago
LICENSE typescript rewrite (v2) 6 years ago
README.md align comments 6 years ago
package.json 2.0.1 6 years ago
rollup.config.js typescript rewrite (v2) 6 years ago
tsconfig.json typescript rewrite (v2) 6 years ago
yarn.lock typescript rewrite (v2) 6 years ago

README.md

lua-in-js

npm PRs Welcome GitHub   Badges are clickable!

A Lua to JS transpiler/runtime. This library is a rewrite of Starlight with a lot of improvements.

Install

npm i lua-in-js

API

Import

const luainjs = require(luainjs)
// or
import luainjs from 'luainjs'

Create the lua environment

Lua environments are isolated from each other (they got different global scopes)

const luaEnv = luainjs.createEnv()

A config object can be passed in for extra functionality

const luaEnv = luainjs.createEnv({
    LUA_PATH,   // default value of package.path
    fileExists, // function that takes in a path and returns a boolean
    loadFile,   // function that takes in a path and returns the content of a file
    stdin,      // string representing the standard input
    stdout,     // function representing the standard output
    osExit      // function called by os.exit
})

Run a script or file

luaEnv.run('print(\'Hello world!\')')
luaEnv.runfile('somefile.lua')

runfile uses config.fileExists and config.loadFile

Example

Check out the test runner for a concrete example.

Missing functionality

  • coroutine library
  • debug library
  • utf8 library
  • io library
  • package.cpath
  • package.loadlib
  • string.dump
  • string.pack
  • string.packsize
  • string.unpack
  • os.clock
  • os.execute
  • os.getenv
  • os.remove
  • os.rename
  • os.tmpname