2 * Copyright (C) 2012,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/>.
29 #include "_quvi_script_s.h"
37 * NOTE: The error messages produced in these functions are intended for
38 * developers. They would typically be seen when a new script is being
41 * The messages should be clear, indicating the actual error, minimizing
42 * the time spent on locating the actual problem in the script.
45 gboolean
l_chk_can_parse_url(lua_State
*l
, _quvi_script_t qs
,
46 const gchar
*k_can_parse_url
,
47 const gchar
*k_domains
,
48 const gchar
*script_func
)
53 while (lua_next(l
, LI_KEY
))
55 l_chk_assign_s(l
, k_domains
, qs
->domains
, TRUE
, FALSE
);
56 l_chk_assign_b(l
, k_can_parse_url
, &r
);
59 if (qs
->domains
->len
==0)
61 luaL_error(l
, "%s: %s: the returned dictionary must contain "
62 "a string value `%s'",
63 qs
->fpath
->str
, script_func
, k_domains
);
69 * Return the value of the named (`w') string. The value is trimmed
70 * of any extra whitespace (e.g. leading, trailing).
72 * NOTE: g_free the returned value when done using it.
74 gboolean
l_chk_s(lua_State
*l
, const gchar
*w
, gchar
**v
,
75 gboolean trim_flag
, gboolean escape_url
)
77 if (lua_isstring(l
, LI_KEY
) && lua_isstring(l
, LI_VALUE
))
79 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
81 const gchar
*s
= lua_tostring(l
, LI_VALUE
);
82 *v
= (trim_flag
== TRUE
)
85 if (escape_url
== TRUE
)
87 gchar
*e
= m_url_escaped_form(*v
);
97 gboolean
l_chk_assign_s(lua_State
*l
, const gchar
*k
, GString
*v
,
98 gboolean trim_flag
, gboolean escape_url
)
101 if (l_chk_s(l
, k
, &s
, trim_flag
, escape_url
) == TRUE
)
103 g_string_assign(v
, s
);
110 gboolean
l_chk_n(lua_State
*l
, const gchar
*w
, gdouble
*v
)
112 if (lua_isstring(l
, LI_KEY
) && lua_isnumber(l
, LI_VALUE
))
114 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
116 *v
= lua_tonumber(l
, LI_VALUE
);
123 gboolean
l_chk_assign_n(lua_State
*l
, const gchar
*k
, gdouble
*v
)
126 if (l_chk_n(l
, k
, &n
) == TRUE
)
134 gboolean
l_chk_b(lua_State
*l
, const gchar
*w
, gboolean
*v
)
136 if (lua_isstring(l
, LI_KEY
) && lua_isboolean(l
, LI_VALUE
))
138 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
140 *v
= lua_toboolean(l
, LI_VALUE
);
147 gboolean
l_chk_assign_b(lua_State
*l
, const gchar
*k
, gboolean
*v
)
150 if (l_chk_b(l
, k
, &b
) == TRUE
)
158 /* vim: set ts=2 sw=2 tw=72 expandtab: */