I am running Lua with a C++ library via swig. When a swig runtime error occurs I would like to know the line which caused the problem. The error message I receive does not have this information.
How can I find which line in the Lua code triggered the error?
For example suppose I have a swig function “swigstringcount” and it takes a string:
local n=4
local m=swigstringcount(n)
print (m,n)
This (obviously wrong) code produces an error on line two. Currently all I get is
error:SWIG_RuntimeError: swigstringcount requires a string
I want it to tell me that line 2 produced the error, like standard Lua error messages.
Based on this method for getting debug info from the Lua C API I’ve put together a (slightly messy) example of how you can integrate that into a SWIG interface:
This basically replaces the default
SWIG_fail_argmacro with a modified one that gets and prints some debug info.I tested it with the latest SWIG trunk (I think you might be using an older version since the text I see didn’t quite match), but I was able to do:
I seem to have more debug info (i.e. a full stack trace) there already though.