luaload
v0.1.0
Published
A Node.js library for concatenating and loading lua script files in redis
Downloads
1
Readme
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
| Param | Type | Description |
| --- | --- | --- |
| key | String | The key from the mappings. |
| done | function | The final callback. Invoked with (err, sha)
. |
luaload(client, sourceDirectory, mappings, shouldOutput)
The factory method for the LuaScriptLoader.
Kind: global function
| Param | Type | Description |
| --- | --- | --- |
| client | Object | The redis client. |
| sourceDirectory | String | The 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. |
| mappings | Object | An object whose keys are aliases to arrays of file paths to concatenate. |
| shouldOutput | Boolean | If 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