A proof of concept application server that can serve lua applications. It uses gopher-lua
- Load lua code
- Proxy calls from Go to lua
- Build Go packages/functions that is callable from Lua packages
- Build a RESP (redis) transport so remote clients can call lua functions
- Basic control resp command to list, load, and unload lua packages
- Client sets
content-type
current onlyJSON
- Test support for native lua libraries
- Authentication/Authorization
- Package manifest to configure
- Authentication/Authorization per package (action?)
- Go packages to be available from Lua package
While the code base supports replacing and or add support to multiple transport layers, currently only Resp transport is implemented. It works as following
- Resp expose built in functions, and packages functions
- All built it functions are prefixed with
.
, and they are case insensitive - Currently the build in functions are
.ping
response is alwaysPONG
.package.list
list names of loaded packages.package.add <name> <path>
adds lua package add pathpath
with namename
.package.remove <name>
remove packagesname
.content-type.get
gets current content type (currently only returnJSON
).content-type.set
sets content type for package method calls inputs and outputs (current only return errornot implemented
)
- Package functions calls
- Package functions calls has to be in format
<package>.<function> args...
- arguments must be valid value for selected
content-type
(currently json) - Note: the following examples are done with
redis-cli -p 9091
- for example a call to
add
function of thecalc
package must be done ascalc.add 1 2
notice that inputs are not quoted because that's how a valid json number is. The return value is always a valid json value. You need to unmarshal the returned data to get a valid type. - for a bit of a more complex example, the
db
packagedb.set
anddb.get
always require a string keydb.set '"key"' '"string value"
sets value to string valuedb.set '"key"' 123
sets value to numeric valuedb.get '"key"'
returns the last set value tokey
- Note here a valid json string
key
is"key"
- Package functions calls has to be in format
In one terminal do
make run
In another terminal do
redis-cli -p 9091
Then in the redis-cli shell, do:
> .ping
PONG
List loaded packages
> .package.list
1) calc
2) db
Make a call
> calc.add 1 2
"3"
> db.set '"name"' '"test"'
OK
> db.set '"age"' 37
OK
> db.get '"name"'
"\"test\""
> db.get '"age"'
"37
The escape sequence is added by redis-cli
for display purpose, with a redis client, you will receive a valid json string that you can unmarshal normally