2 * Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
22 * NOTE: The error messages produced in these functions are intended for
23 * developers. They would typically be seen when a new script is
24 * being developed or an old one is being maintained.
26 * These messages should be clear, indicating the actual error,
27 * minimizing the time spent on locating the problem in the script.
38 #include "_quvi_subtitle_export_s.h"
39 #include "_quvi_script_s.h"
41 #include "lua/setfield.h"
45 static const gchar script_func
[] = "ident";
47 static QuviError
_chk_results(lua_State
*l
, _quvi_script_t qs
)
52 while (lua_next(l
, LI_KEY
))
54 l_chk_assign_s(l
, SUES_EXPORT_FORMAT
, qs
->export
.format
, TRUE
, FALSE
);
55 l_chk_assign_b(l
, SUES_CAN_EXPORT_DATA
, &r
);
59 if (qs
->export
.format
->len
==0)
61 luaL_error(l
, "%s: %s: the returned dictionary must contain "
62 "a string value `%s'",
63 qs
->fpath
->str
, script_func
, SUES_EXPORT_FORMAT
);
69 : QUVI_ERROR_NO_SUPPORT
);
72 QuviError
l_exec_subtitle_export_script_ident(gpointer p
, GSList
*sl
)
74 _quvi_subtitle_export_t qse
;
78 qse
= (_quvi_subtitle_export_t
) p
;
79 l
= qse
->handle
.quvi
->handle
.lua
;
81 qs
= (_quvi_script_t
) sl
->data
;
84 if (luaL_dofile(l
, qs
->fpath
->str
))
85 luaL_error(l
, "%s", lua_tostring(l
, -1));
87 lua_getglobal(l
, script_func
);
89 if (!lua_isfunction(l
, -1))
91 static const gchar
*_E
= "%s: the function `%s' was not found";
92 luaL_error(l
, _E
, qs
->fpath
->str
, script_func
);
96 l_setfield_s(l
, SUES_TO_FORMAT
, qse
->format
.to
->str
, -1);
98 if (lua_pcall(l
, 1, 1, 0))
100 g_string_assign(qse
->handle
.quvi
->status
.errmsg
, lua_tostring(l
, -1));
101 return (QUVI_ERROR_SCRIPT
);
104 if (!lua_istable(l
, -1))
106 luaL_error(l
, "%s: %s: must return a dictionary",
107 qs
->fpath
->str
, script_func
);
109 return (_chk_results(l
, qs
));
112 /* vim: set ts=2 sw=2 tw=72 expandtab: */