From 6d001f4894b0d68f34ec488056934243bc0090c6 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Fri, 5 Feb 2016 15:16:36 +0100 Subject: [PATCH] Extra description about debugging Lua issues in readme. --- README.md | 11 +++++++++++ src/conf_defaults.lua | 2 ++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index b96cfa0..5e1513d 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,14 @@ The script 'doxify.sh' generates HTML documentation of the source code in the di Make sure the 'ldoc' program is installed on your machine and the LDOC variable in the script points there. On OSX, this can be accomplished by installing it through luarocks (run `sudo luarocks install ldoc`). Luarocks can be installed using [MacPorts](http://www.macports.org/). After installing that, the command would be `sudo port install luarocks`. + + +Debugging Lua +------------- + +Syntax errors in Lua can lead to tricky issues since they might only surface when the faulty code is actually being run. + +One countermeasure for this is to use [pcall](http://www.lua.org/pil/8.4.html) instead of regular calls in many cases. To let the error 'happen' (which in turn gives information in the form of stack traces), tell the code to use regular calls by setting 'M.DEBUG_PCALLS' to 'true' in `conf_defaults.lua`. + +A second way of debugging is to take uhttpd out of the loop and invoke the Lua code from command-line. To do this, set 'M.DEBUG_API' to 'true' in `conf_defaults.lua`. Then invoke the API using the command `d3dapi p=/mod/func r=POST` where `p=` is followed by the API path and `r=` followed by either 'GET' or 'POST'. +Be aware though, that this script redirects output streams to a fallback log file where stack traces will end up, this file is `/tmp/wifibox.cgi-fallback.log`. diff --git a/src/conf_defaults.lua b/src/conf_defaults.lua index 2487b57..5dd9093 100644 --- a/src/conf_defaults.lua +++ b/src/conf_defaults.lua @@ -36,6 +36,8 @@ M.DEBUG_PCALLS = false --- This constant enables debugging of the REST API from the command-line by emulating GET/POST requests. -- Specify the path and optionally the request method as follows: `d3dapi p=/mod/func r=POST`. +-- Note that the command-line script redirects the output streams to '/tmp/wifibox.cgi-fallback.log' +-- meaning that any stack traces can be found there. M.DEBUG_API = true --- If enabled, REST responses will contain 'module' and 'function' keys describing what was requested.