Skip to content

Zeyu-Li/lua-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lua Runner

License: MIT npm version download count badge

A node module that runs Lua code with the power of webassembly!

About

Run your Lua code right inside of JavaScript or TypeScript with this module. Made from wasm_lua

  • Lua 5.4.0
  • TypeScript support
  • 0 dependencies
  • Tests
  • Browser support

Installation

To install do

npm i lua-runner --save

Usage

To use the module

// import the package
import {run_lua} from "lua-runner"

// define the lua code
let testLuaCode = `    
function hello_lua()
    print("Hello World!")
    return "A"
end
return hello_lua()
`

// run the code with the run_lua function and use then to catch the response
run_lua(testLuaCode).then(res=> {
    console.log(res)
})

or without ES6 syntax as

let { run_lua } = require("lua-runner");

let testLuaCode = `    
function hello_lua()
    print("Hello World!")
    return "A"
end
return hello_lua()
`;

run_lua(testLuaCode).then(function (res) {
    console.log(res);
});

lua runner also has a function that returns a response object in the form of the following

interface response {
    return?: string
    exit_code?: string
}

This function call is run_lua_res instead of run_lua

let { run_lua_res } = require("lua-runner");

let testLuaCode = `    
function hello_lua()
    print("Hello World!")
    return "A"
end
return hello_lua()
`;

run_lua_res(testLuaCode).then(function (res) {
    console.log(res);
});

Author

License

License: MIT

License under MIT, check out Lua at lua.org