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/>.
29 #include "_quvi_script_s.h"
36 * NOTE: The error messages produced in these functions are intended for
37 * developers. They would typically be seen when a new script is being
40 * The messages should be clear, indicating the actual error, minimizing
41 * the time spent on locating the actual problem in the script.
44 gboolean
l_chk_can_parse_url(lua_State
*l
, _quvi_script_t qs
,
45 const gchar
*k_can_parse_url
,
46 const gchar
*k_domains
,
47 const gchar
*script_func
)
52 while (lua_next(l
, LI_KEY
))
54 l_chk_assign_s(l
, k_domains
, qs
->domains
, TRUE
);
55 l_chk_assign_b(l
, k_can_parse_url
, &r
);
58 if (qs
->domains
->len
==0)
60 luaL_error(l
, "%s: %s: the returned dictionary must contain "
61 "a string value `%s'",
62 qs
->fpath
->str
, script_func
, k_domains
);
68 * Return the value of the named (`w') string. The value is trimmed
69 * of any extra whitespace (e.g. leading, trailing).
71 * NOTE: g_free the returned value when done using it.
73 gboolean
l_chk_s(lua_State
*l
, const gchar
*w
, gchar
**v
, gboolean trim_flag
)
75 if (lua_isstring(l
, LI_KEY
) && lua_isstring(l
, LI_VALUE
))
77 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
79 const gchar
*s
= lua_tostring(l
, LI_VALUE
);
80 *v
= (trim_flag
== TRUE
)
89 gboolean
l_chk_assign_s(lua_State
*l
, const gchar
*k
, GString
*v
,
93 if (l_chk_s(l
, k
, &s
, trim_flag
) == TRUE
)
95 g_string_assign(v
, s
);
102 gboolean
l_chk_n(lua_State
*l
, const gchar
*w
, gdouble
*v
)
104 if (lua_isstring(l
, LI_KEY
) && lua_isnumber(l
, LI_VALUE
))
106 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
108 *v
= lua_tonumber(l
, LI_VALUE
);
115 gboolean
l_chk_assign_n(lua_State
*l
, const gchar
*k
, gdouble
*v
)
118 if (l_chk_n(l
, k
, &n
) == TRUE
)
126 gboolean
l_chk_b(lua_State
*l
, const gchar
*w
, gboolean
*v
)
128 if (lua_isstring(l
, LI_KEY
) && lua_isboolean(l
, LI_VALUE
))
130 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
132 *v
= lua_toboolean(l
, LI_VALUE
);
139 gboolean
l_chk_assign_b(lua_State
*l
, const gchar
*k
, gboolean
*v
)
142 if (l_chk_b(l
, k
, &b
) == TRUE
)
150 /* vim: set ts=2 sw=2 tw=72 expandtab: */