You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

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

0.1.3
latest
Source
npmnpm
Version published
Weekly downloads
699K
-5.28%
Maintainers
2
Weekly downloads
 
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

lua

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