项目作者: Zeyu-Li

项目描述 :
A npm package to run Lua
高级语言: TypeScript
项目地址: git://github.com/Zeyu-Li/lua-runner.git
创建时间: 2021-03-27T20:21:46Z
项目社区:https://github.com/Zeyu-Li/lua-runner

开源协议:MIT License

下载


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

  1. // import the package
  2. import {run_lua} from "lua-runner"
  3. // define the lua code
  4. let testLuaCode = `
  5. function hello_lua()
  6. print("Hello World!")
  7. return "A"
  8. end
  9. return hello_lua()
  10. `
  11. // run the code with the run_lua function and use then to catch the response
  12. run_lua(testLuaCode).then(res=> {
  13. console.log(res)
  14. })

or without ES6 syntax as

  1. let { run_lua } = require("lua-runner");
  2. let testLuaCode = `
  3. function hello_lua()
  4. print("Hello World!")
  5. return "A"
  6. end
  7. return hello_lua()
  8. `;
  9. run_lua(testLuaCode).then(function (res) {
  10. console.log(res);
  11. });

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

  1. interface response {
  2. return?: string
  3. exit_code?: string
  4. }

This function call is run_lua_res instead of run_lua

  1. let { run_lua_res } = require("lua-runner");
  2. let testLuaCode = `
  3. function hello_lua()
  4. print("Hello World!")
  5. return "A"
  6. end
  7. return hello_lua()
  8. `;
  9. run_lua_res(testLuaCode).then(function (res) {
  10. console.log(res);
  11. });

Author

License

License: MIT

License under MIT, check out Lua at lua.org