From f047cc93b9c8ef2b81bc692af3a2868969992bdf Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 19 Oct 2013 23:52:24 +0000 Subject: Remove all calls to 'module' in preparation for move to Lua 5.2 Use mymodule parameter for module definition. This was also helpful in revealing places where the code relied on the global environment. --- freeswitch-model.lua | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'freeswitch-model.lua') diff --git a/freeswitch-model.lua b/freeswitch-model.lua index ffdc699..4e2b140 100644 --- a/freeswitch-model.lua +++ b/freeswitch-model.lua @@ -1,4 +1,4 @@ -module (..., package.seeall) +local mymodule = {} -- Load libraries modelfunctions = require("modelfunctions") @@ -23,33 +23,33 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -get_status = function() +mymodule.get_status = function() return modelfunctions.getstatus(processname, packagename, "Freeswitch Status") end -function get_startstop(self, clientdata) +function mymodule.get_startstop(self, clientdata) return modelfunctions.get_startstop(processname) end -function startstop_service(self, startstop, action) +function mymodule.startstop_service(self, startstop, action) return modelfunctions.startstop_service(startstop, action) end -function getreloadxml() +function mymodule.getreloadxml() return cfe({ type="group", value={}, label="Reload Freeswitch XML" }) end -function reload_xml(self, relo) +function mymodule.reload_xml(self, relo) relo.descr, relo.errtxt = modelfunctions.run_executable({"fs_cli", "-x", "reloadxml"}, true) return relo end -get_file = function(self, clientdata) +mymodule.get_file = function(self, clientdata) local filename = clientdata.filename return modelfunctions.getfiledetails(filename, is_valid_filename) end -update_file = function(self, filedetails) +mymodule.update_file = function(self, filedetails) local ret = modelfunctions.setfiledetails(self, filedetails, is_valid_filename) if not ret.errtxt then posix.chmod(filedetails.value.filename.value, "rw-------") @@ -58,7 +58,7 @@ update_file = function(self, filedetails) return ret end -list_files = function() +mymodule.list_files = function() local retval = {} for file in fs.find(null, baseurl) do local details = fs.stat(file) @@ -71,12 +71,12 @@ list_files = function() return cfe({ type="structure", value=retval, label="List of Freeswitch files" }) end -function getnewfile() +function mymodule.getnewfile() local filename = cfe({ label="File Name", descr="Must be in "..baseurl }) return cfe({ type="group", value={filename=filename}, label="Freeswitch File" }) end -function createfile(self, filedetails) +function mymodule.createfile(self, filedetails) local success = true local path = string.match(filedetails.value.filename.value, "^%s*(.*%S)%s*$") or "" if not string.find(path, "/") then @@ -103,15 +103,15 @@ function createfile(self, filedetails) return filedetails end -function getdeletefile(self, clientdata) +function mymodule.getdeletefile(self, clientdata) local retval = {} retval.filename = cfe({ label="File Name", value=clientdata.filename or "" }) return cfe({ type="group", value=retval, label="Delete Freeswitch File" }) end -function deletefile(self, delfile) +function mymodule.deletefile(self, delfile) delfile.errtxt = "Failed to delete Freeswitch File - invalid filename" - for i,file in ipairs(list_files().value) do + for i,file in ipairs(mymodule.list_files().value) do if delfile.value.filename.value == file.filename then delfile.errtxt = nil os.remove(delfile.value.filename.value) @@ -121,3 +121,5 @@ function deletefile(self, delfile) return delfile end + +return mymodule -- cgit v1.2.3