OpenResty - LUA module

This assumes you have installed OpenResty on a Linux system.

Let's say you have a module named core.lua that contains the following.

local _foo = {}

function _foo.hello() print("Hello") end
function _foo.world() print("World") end

return _foo

 

The resty command can be used to invoke the core.lua module. If the core.lua module is in your present working directory, here is how you would invoke the "hello" function.

~]# resty -e 'require "core".hello()'
Hello

 

Or the "world" function.

~]# resty -e 'require "core".world()'
World

 

If core.lua is not in your present working directory, the -I option can be used to point to the directory that contains core.lua.

~]# resty -I /usr/local/share/lua -e 'require "core".hello()'
Hello

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 1a24b in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |