2 * Copyright (C) 2012 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_media_s.h"
39 #include "_quvi_script_s.h"
41 #include "lua/getfield.h"
42 #include "lua/setfield.h"
46 static const gchar script_func
[] = "ident";
48 static QuviError
_chk_results(lua_State
*l
, _quvi_script_t qs
)
52 r
= (l_chk_can_parse_url(l
, qs
, MS_CAN_PARSE_URL
,
53 MS_DOMAINS
, script_func
) == TRUE
)
55 : QUVI_ERROR_NO_SUPPORT
;
61 QuviError
l_exec_media_script_ident(gpointer p
, GSList
*sl
)
67 qm
= (_quvi_media_t
) p
;
68 l
= qm
->handle
.quvi
->handle
.lua
;
71 qs
= (_quvi_script_t
) sl
->data
;
73 if (luaL_dofile(l
, qs
->fpath
->str
))
74 luaL_error(l
, "%s", lua_tostring(l
, -1));
76 lua_getglobal(l
, script_func
);
78 if (!lua_isfunction(l
, -1))
80 luaL_error(l
, "%s: the function `%s' was not found",
81 qs
->fpath
->str
, script_func
);
85 l_setfield_s(l
, MS_INPUT_URL
, qm
->url
.input
->str
, -1);
87 if (lua_pcall(l
, 1, 1, 0))
89 g_string_assign(qm
->handle
.quvi
->status
.errmsg
, lua_tostring(l
, -1));
90 return (QUVI_ERROR_SCRIPT
);
93 if (!lua_istable(l
, -1))
95 luaL_error(l
, "%s: %s: must return a dictionary",
96 qs
->fpath
->str
, script_func
);
98 return (_chk_results(l
, qs
));
101 /* vim: set ts=2 sw=2 tw=72 expandtab: */