diff --git a/src/API.cpp b/src/API.cpp index 26bf558c0..0815d933f 100644 --- a/src/API.cpp +++ b/src/API.cpp @@ -188,28 +188,35 @@ static int api_task_get_footnote_messages () } //////////////////////////////////////////////////////////////////////////////// -static int api_task_get_debug_messages () -{ - return {} -} - -//////////////////////////////////////////////////////////////////////////////// --- Records additional messages, for subsequent display. -static int api_task_header_message (text) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_footnote_message (text) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_debug_message (text) +static int api_task_get_debug_messages (lua_State* L) { } */ +//////////////////////////////////////////////////////////////////////////////// +static int api_task_header_message (lua_State* L) +{ + std::string message = luaL_checkstring (L, 1); + context.header (message); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +static int api_task_footnote_message (lua_State* L) +{ + std::string message = luaL_checkstring (L, 1); + context.footnote (message); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +static int api_task_debug_message (lua_State* L) +{ + std::string message = luaL_checkstring (L, 1); + context.debug (message); + return 0; +} + //////////////////////////////////////////////////////////////////////////////// // Causes the shell or interactive mode task to exit. Ordinarily this does not // occur. @@ -542,10 +549,10 @@ void API::initialize () lua_pushcfunction (L, api_task_get_header_messages); lua_setglobal (L, "task_get_header_messages"); lua_pushcfunction (L, api_task_get_footnote_messages); lua_setglobal (L, "task_get_footnote_messages"); lua_pushcfunction (L, api_task_get_debug_messages); lua_setglobal (L, "task_get_debug_messages"); +*/ lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message"); lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message"); lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message"); -*/ lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit"); /* lua_pushcfunction (L, api_task_inhibit_further_hooks); lua_setglobal (L, "task_inhibit_further_hooks"); diff --git a/src/tests/hook.api.task_debug.t b/src/tests/hook.api.task_debug.t new file mode 100755 index 000000000..70277639a --- /dev/null +++ b/src/tests/hook.api.task_debug.t @@ -0,0 +1,78 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "debug=on\n", + "hook.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () task_debug_message ('DEBUG MESSAGE') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/DEBUG MESSAGE/ms, 'Hook called task_debug_message'); +} +else +{ + pass ('Hook called task_debug_message - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.api.task_footnote.t b/src/tests/hook.api.task_footnote.t new file mode 100755 index 000000000..5f7268470 --- /dev/null +++ b/src/tests/hook.api.task_footnote.t @@ -0,0 +1,77 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () task_footnote_message ('FOOTNOTE MESSAGE') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/FOOTNOTE MESSAGE/ms, 'Hook called task_footnote_message'); +} +else +{ + pass ('Hook called task_footnote_message - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.api.task_header.t b/src/tests/hook.api.task_header.t new file mode 100755 index 000000000..1f215fdee --- /dev/null +++ b/src/tests/hook.api.task_header.t @@ -0,0 +1,77 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () task_header_message ('HEADER MESSAGE') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/HEADER MESSAGE/ms, 'Hook called task_header_message'); +} +else +{ + pass ('Hook called task_header_message - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; +