Socket
Socket
Sign inDemoInstall

fengari

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fengari

A Lua VM written in JS ES6 targeting the browser


Version published
Weekly downloads
439K
decreased by-2.82%
Maintainers
2
Weekly downloads
 
Created

What is fengari?

Fengari is a JavaScript implementation of the Lua programming language. It allows you to run Lua code within a JavaScript environment, making it possible to leverage Lua's simplicity and efficiency in web applications or Node.js projects.

What are fengari's main functionalities?

Running Lua code

This feature allows you to run Lua code directly from JavaScript. The code sample demonstrates how to initialize a Lua state, open standard libraries, and execute a Lua script that prints a message.

const fengari = require('fengari');
const lua = fengari.lua;
const lauxlib = fengari.lauxlib;
const lualib = fengari.lualib;

const L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
lauxlib.luaL_dostring(L, 'print("Hello from Lua!")');

Interoperability between Lua and JavaScript

This feature demonstrates how to call JavaScript functions from Lua. The code sample shows how to push a JavaScript function onto the Lua stack and call it from Lua code.

const fengari = require('fengari');
const lua = fengari.lua;
const lauxlib = fengari.lauxlib;
const lualib = fengari.lualib;

const L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);

lua.lua_pushjsfunction(L, function(L) {
  console.log('Hello from JavaScript!');
  return 0;
});
lua.lua_setglobal(L, 'jsFunction');
lauxlib.luaL_dostring(L, 'jsFunction()');

Embedding Lua scripts in JavaScript

This feature allows you to embed Lua scripts within JavaScript code. The code sample demonstrates how to define a Lua function in a script and call it from JavaScript.

const fengari = require('fengari');
const lua = fengari.lua;
const lauxlib = fengari.lauxlib;
const lualib = fengari.lualib;

const L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);

const luaScript = `
function greet(name)
  return 'Hello, ' .. name .. '!'
end
`;
lauxlib.luaL_dostring(L, luaScript);
lauxlib.luaL_dostring(L, 'print(greet("World"))');

Other packages similar to fengari

Keywords

FAQs

Package last updated on 18 Nov 2018

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