2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "_quvi_media_s.h"
29 #include "_quvi_script_s.h"
31 #include "lua/getfield.h"
32 #include "lua/setfield.h"
37 * NOTE: The error messages produced in these functions are intended for
38 * developers. They would typically be seen when a new media script is
41 * The messages should be clear, indicating the actual error, minimizing
42 * the time spent on locating the actual problem in the script.
45 static const gchar script_func
[] = "ident";
47 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))
79 luaL_error(l
, "%s: function `%s' not found", qs
->fpath
->str
, script_func
);
82 l_setfield_b(l
, GS_VERBOSE
, qm
->handle
.quvi
->opt
.scripts
.verbose
);
83 l_setfield_s(l
, MS_INPUT_URL
, qm
->url
.input
->str
);
85 if (lua_pcall(l
, 1, 1, 0))
87 g_string_assign(qm
->handle
.quvi
->status
.errmsg
, lua_tostring(l
, -1));
88 return (QUVI_ERROR_SCRIPT
);
91 if (!lua_istable(l
, -1))
93 luaL_error(l
, "%s: %s: must return a dictionary",
94 qs
->fpath
->str
, script_func
);
96 return (_chk_results(l
, qs
, qm
));
99 /* vim: set ts=2 sw=2 tw=72 expandtab: */