Socket
Socket
Sign inDemoInstall

fengari-interop

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fengari-interop

JS library for Fengari


Version published
Maintainers
2
Created

What is fengari-interop?

The fengari-interop npm package provides interoperability between JavaScript and Lua, allowing you to run Lua code from JavaScript and vice versa. It is built on top of Fengari, a Lua VM written in JavaScript.

What are fengari-interop's main functionalities?

Running Lua code from JavaScript

This feature allows you to execute Lua code directly from JavaScript. The code sample demonstrates how to load and run a simple Lua script that prints a message.

const fengari = require('fengari');
const interop = require('fengari-interop');
const luaCode = `
  print('Hello from Lua!')
`;
const L = fengari.L;
fengari.luaL_loadstring(L, fengari.to_luastring(luaCode));
fengari.lua_call(L, 0, 0);

Calling JavaScript functions from Lua

This feature allows Lua code to call JavaScript functions. The code sample shows how to call the JavaScript `print` function from within Lua code.

const fengari = require('fengari');
const interop = require('fengari-interop');
const luaCode = `
  js.global:print('Hello from Lua calling JS!')
`;
const L = fengari.L;
interop.luaopen_js(L);
fengari.luaL_loadstring(L, fengari.to_luastring(luaCode));
fengari.lua_call(L, 0, 0);

Accessing JavaScript objects from Lua

This feature allows Lua code to create and manipulate JavaScript objects. The code sample demonstrates creating a JavaScript object in Lua, setting a property, and then accessing that property.

const fengari = require('fengari');
const interop = require('fengari-interop');
const luaCode = `
  local obj = js.new(js.global.Object)
  obj.foo = 'bar'
  print(obj.foo)
`;
const L = fengari.L;
interop.luaopen_js(L);
fengari.luaL_loadstring(L, fengari.to_luastring(luaCode));
fengari.lua_call(L, 0, 0);

Other packages similar to fengari-interop

Keywords

FAQs

Package last updated on 29 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc