npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

luanode-runtime

v0.1.0

Published

Allows you to load and call lua scripts and directories on demand

Downloads

7

Readme

LuaNode-Runtime

A quickly hacked together framework for running Lua projects and scripts in a nodejs environment without any dependencies or other nonsense, adapted from lua.vm.js.

Most of the credit should go to http://kripken.github.io/lua.vm.js/lua.vm.js.html, I'm mostly just packaging it up.

LuaNode-Runtime is being built for eventual use with https://github.com/danShumway/Piglet. All of my maintenance and upkeep will revolve around that project - therefore I might not always be the most timely to get an issue fixed or to package something. Use with caution, this is finished enough for my usage, not necessarily yours.

Installation

npm install luanode-runtime

Usage

var lua = require('luanode-runtime');

//Loads all of the lua files in a given directory (recurses into subdirectory) to an internal directory of your choice.
//I recommend using path.resolve(__dirname + "/local/path/from/script"), to simplify and remove errors.
//Once loaded, you can call scripts from Lua using dofile('internal_path/file.lua')
//It's possible this may load other files as well, and maybe that's a thing you want for internal lua referencing?  So many possiblities!
lua.loadDirectory(directory_path, intenal_path, callback);

//See above, except with a file.
lua.loadFile(directory_path, internal_path, callback);

//Executes a lua script, and then runs the given callback.
//Pass in your script as a string.
lua.runScript(lua_script, callback);

//See above, except you pass in a previously loaded file instead.
//This will reference the path you loaded to, not the actual path.
//So if you ran - 
//lua.loadDirectory(path.resolve(__dirname + "/myScripts", "iPath", function(err) { });
//You would then run - 
//lua.runLoadedScript("iPath/subdirectory/file.lua");
//Not the external path.
lua.runLoadedScript(internal_path, callback);

When an error is thrown by the fileloaders or within the lua script, it is handled differently depending on whether or not a callback was provided. If not provided, the error will be thrown as normal. Otherwise, the callback will be called immediately and passed the error.

//This will throw an exception in lua (cannot add string and number)
lua.runScript("print('a' + 1)", function(err){
  if(err) {
    console.log("LUA ERROR: " + err.message);
  }
});

Javascript can insert variables and methods into Lua scope

var lua = require('luanode-runtime');

//Pass in a name, and the object that you want to send.
lua.setGlobal("jsVar", "hello from javascript");
lua.setGlobal("jsMethod", function(str) { console.log(str); });

Lua scripts can now access a global scope at js.global

print(js.global.jsVar) --prints "hello from javascript"
js.global.newLuaVar = "hello from lua" --Will now be accessible from within javascript.
js.global:jsMethod("My Lua string"); --Note the syntax difference.
console.log(lua.getGlobal("newLuaVar")); //Prints "hello from lua"

You can see a complete working example in tests/index.js