0.1.0 • Published 7 years ago

luaload v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

luaload

A Node.js library for concatenating and loading lua script files in redis

Please, refer to the Installation, Usage, API, Requirements and License sections for more information.

Installation

npm install luaload

Usage

./usage.js

const luaload = require('luaload')
const redis = require('redis')

const client = redis.createClient()
const sourceDirectory = path.join(__dirname, './lua')
const mappings = {
    ninja_turtles: [
        'leonardo',
        'michelangelo',
        'donatello',
        'raphael',
        'list_ninja_turtles'
    ],
}
const shouldOutput = true

const loader = luaload(client, sourceDirectory, mappings, shouldOutput)

loader.load('list_ninja_turtles', (err, sha) => {
    if (err) {
        throw err
    }

    client.evalsha(sha, 0, (err, reply) => {
        if (err) {
            throw err
        }

        console.log(reply) // ['donatello', 'leonardo', 'michelangelo', 'raphael']
    })
})

./lua/donatello.lua

local function donatello()
    return 'Donatello'
end

./lua/leonardo.lua

local function leonardo()
    return 'Leonardo'
end

./lua/michelangelo.lua

local function michelangelo()
    return 'Michelangelo'
end

./lua/raphael.lua

local function raphael()
    return 'Raphael'
end

./lua/list_ninja_turtles.lua

local return_value = {}

table.insert(return_value, donatello())
table.insert(return_value, leonardo())
table.insert(return_value, michelangelo())
table.insert(return_value, raphael())

return return_value

API

Classes

Functions

LUAScriptLoader

The script loader.

Kind: global class

luaScriptLoader.load(key, done)

Concatenates and loads a script from files. Returns the SHA-1 digest of the script.

Kind: instance method of LUAScriptLoader

ParamTypeDescription
keyStringThe key from the mappings.
donefunctionThe final callback. Invoked with (err, sha).

luaload(client, sourceDirectory, mappings, shouldOutput)

The factory method for the LuaScriptLoader.

Kind: global function

ParamTypeDescription
clientObjectThe redis client.
sourceDirectoryStringThe absolute path to the directory containing the lua script files to concatenate and load. The directory should exist. The Directory should be readable. If shouldOutput is set to true, then the directory should also be writable.
mappingsObjectAn object whose keys are aliases to arrays of file paths to concatenate.
shouldOutputBooleanIf set to true, the concatenated script file will be written to sourceDirectory.

Requirements

  • Node.js 6+
  • Redis 2.8.9+

License

This project is MIT-licensed