All Projects → teoxoy → lua-in-js

teoxoy / lua-in-js

Licence: MIT license
A Lua to JS transpiler / runtime

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to lua-in-js

cotowali
A statically typed scripting language that transpile into POSIX sh
Stars: ✭ 551 (+1389.19%)
Mutual labels:  transpiler
blueboat
All-in-one, multi-tenant serverless JavaScript runtime.
Stars: ✭ 1,832 (+4851.35%)
Mutual labels:  runtime
AutoWIG
Automatic Wrapper and Interface Generator
Stars: ✭ 107 (+189.19%)
Mutual labels:  transpiler
Py2Jl.jl
Python to Julia transpiler.
Stars: ✭ 67 (+81.08%)
Mutual labels:  transpiler
quickjs-build
Build for QuickJS JavaScript Engine
Stars: ✭ 25 (-32.43%)
Mutual labels:  runtime
bashscript
TypeScript to bash transpiler. Because.
Stars: ✭ 37 (+0%)
Mutual labels:  transpiler
Gloa
Glóa - a statically typed language that compiles to Lua. *UNDER DEVELOPMENT*
Stars: ✭ 19 (-48.65%)
Mutual labels:  transpiler
hex
An ecosystem delivering practices, philosophy and portability. Powered By Deno and JavaScript.
Stars: ✭ 48 (+29.73%)
Mutual labels:  runtime
Craxe
Haxe to nim transpiler
Stars: ✭ 39 (+5.41%)
Mutual labels:  transpiler
phpify
Compiles PHP modules for the browser with Uniter.
Stars: ✭ 18 (-51.35%)
Mutual labels:  transpiler
kithon
Python to any languages transpiler
Stars: ✭ 33 (-10.81%)
Mutual labels:  transpiler
RuntimeBPs
This project allows for visual scripting in UE4 similar to Blueprints, but at runtime. The way this is set up does not make use of any UE4 boilerplate and could with a few adjustments be used in another engine.
Stars: ✭ 77 (+108.11%)
Mutual labels:  runtime
purenix
Nix backend for PureScript. Transpile PureScript code to Nix.
Stars: ✭ 227 (+513.51%)
Mutual labels:  transpiler
node-mini
Mini Node.js runtime built on V8
Stars: ✭ 24 (-35.14%)
Mutual labels:  runtime
claw-compiler
CLAW Compiler for Performance Portability
Stars: ✭ 38 (+2.7%)
Mutual labels:  transpiler
transpiler
ABAP to JS transpiler
Stars: ✭ 57 (+54.05%)
Mutual labels:  transpiler
sidef
A modern object-oriented programming language implemented in Perl.
Stars: ✭ 109 (+194.59%)
Mutual labels:  transpiler
WARDuino
A dynamic WebAssembly VM for embedded systems
Stars: ✭ 51 (+37.84%)
Mutual labels:  runtime
iOS11RuntimeHeaders
iOS11RuntimeHeaders
Stars: ✭ 26 (-29.73%)
Mutual labels:  runtime
libclosure-KCBuild
libclosure-74-79编译 - 最新Block底层源码编译,大家可以轻松Block源码调试 查看_Block_copy 还有 __block底层操作...
Stars: ✭ 71 (+91.89%)
Mutual labels:  runtime

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

import * as luainjs from 'lua-in-js'
const luainjs = require('lua-in-js')

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
})

Execute a script or file

const luaScript = luaEnv.parse('print(\'Hello world!\')')
const returnValue = luaScript.exec()
const luaScript = luaEnv.parseFile('somefile.lua')
const returnValue = luaScript.exec()

parseFile uses config.fileExists and config.loadFile

Create a global library

Creating a global library allows you write APIs that you can use in the Lua environment.

function helloBuilder(name) {
    const NAME = luainjs.utils.coerceArgToString(name, 'sayHi', 1)
    return `Hello ${NAME}!`
}

const myLib = new luainjs.Table({ helloBuilder })
luaEnv.loadLib('myLib', myLib)

const helloStr = luaEnv.parse(`return myLib.helloBuilder('John')`).exec()
console.log(helloStr)

Check out the math lib for a more extensive example.

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].