Auto4: Added trace level and format string support to aegisub.debug.out function

Originally committed to SVN as r835.
This commit is contained in:
Niels Martin Hansen 2007-01-18 20:47:56 +00:00
parent b355cf0f3d
commit bbfb0e94d0
5 changed files with 51 additions and 1 deletions

View File

@ -347,6 +347,9 @@ namespace Automation4 {
sizer->SetSizeHints(this);
SetSizer(sizer);
Center();
// Init trace level
trace_level = Options.AsInt(_T("Automation Trace Level"));
}
ProgressSink::~ProgressSink()

View File

@ -236,6 +236,7 @@ namespace Automation4 {
protected:
volatile bool cancelled;
int trace_level;
ProgressSink(wxWindow *parent);
virtual ~ProgressSink();

View File

@ -788,6 +788,32 @@ namespace Automation4 {
int LuaProgressSink::LuaDebugOut(lua_State *L)
{
LuaProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
// Check trace level
if (lua_isnumber(L, 1)) {
int level = lua_tointeger(L, 1);
if (level > ps->trace_level)
return 0;
// remove trace level
lua_remove(L, 1);
}
// Only do format-string handling if there's more than one argument left
// (If there's more than one argument left, assume first is a format string and rest are format arguments)
if (lua_gettop(L) > 1) {
// Format the string
lua_getglobal(L, "string");
lua_getfield(L, -1, "format");
// Here stack contains format string, format arguments, 'string' table, format function
// remove 'string' table
lua_remove(L, -2);
// put the format function into place
lua_insert(L, 1);
// call format function
lua_call(L, lua_gettop(L)-1, 1);
}
// Top of stack is now a string to output
wxString msg(lua_tostring(L, 1), wxConvUTF8);
ps->AddDebugOutput(msg);
return 0;

View File

@ -0,0 +1,17 @@
script_name = "Automation 4 test 9"
script_description = "Test debug out function"
script_author = "Niels Martin Hansen"
script_version = "1"
function test9(subtitles, selected_lines, active_line)
aegisub.debug.out("Only string argument\n")
aegisub.debug.out("Hello %s!\n", "format string world")
aegisub.debug.out("Now going to output 7 strings with trace levels 0 to 6:\n")
for i = 0, 6 do
aegisub.debug.out(i, "Trace level %d...\n", i)
end
aegisub.debug.out(3, "Finished!")
end
aegisub.register_macro("Test debug out", "Tests the aegisub.debug.out function", test9)

View File

@ -69,7 +69,7 @@ Returns: Boolean. True is the user has clicked the Cancel button, false if it
Outputting text to the debug log
function aegisub.debug.out(level, msg, ...)
function aegisub.debug.out([level,] msg, ...)
@level (number)
Integer describing the verbosity of this message. Here are some suggested
@ -85,6 +85,9 @@ function aegisub.debug.out(level, msg, ...)
The level can be used to let the user limit how severe messages will be
shown, so you eg. can leave trace messages in, yet the casual user of the
script won't see them unless he explicitly enables it.
This argument is optional and can be left out, in which case the message
will always be displayed, regardless of the current trace level set in
Aegisub.
@msg (string)
A format string used for the message.