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_script_s.h"
35 * NOTE: The error messages produced in these functions are intended for
36 * developers. They would typically be seen when a new script is being
39 * The messages should be clear, indicating the actual error, minimizing
40 * the time spent on locating the actual problem in the script.
43 gboolean
l_chk_can_parse_url(lua_State
*l
, _quvi_script_t qs
,
44 const gchar
*k_can_parse_url
,
45 const gchar
*k_domains
,
46 const gchar
*script_func
)
51 while (lua_next(l
, LI_KEY
))
53 l_chk_assign_s(l
, k_domains
, qs
->domains
);
54 l_chk_assign_b(l
, k_can_parse_url
, &r
);
57 if (qs
->domains
->len
==0)
59 static const gchar
*_E
=
60 "%s: %s: the dictionary `%s' must contain a string "
63 luaL_error(l
, _E
, qs
->fpath
->str
, script_func
,
64 k_can_parse_url
, k_domains
);
70 * Return the value of the named (`w') string. The value is trimmed
71 * of any extra whitespace (e.g. leading, trailing).
73 * NOTE: g_free the returned value when done using it.
75 gboolean
l_chk_s(lua_State
*l
, const gchar
*w
, gchar
**v
)
77 if (lua_isstring(l
, LI_KEY
) && lua_isstring(l
, LI_VALUE
))
79 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
81 *v
= m_trim_ws(lua_tostring(l
, LI_VALUE
));
88 gboolean
l_chk_assign_s(lua_State
*l
, const gchar
*k
, GString
*v
)
91 if (l_chk_s(l
, k
, &s
) == TRUE
)
93 g_string_assign(v
, s
);
101 gboolean
l_chk_n(lua_State
*l
, const gchar
*w
, gdouble
*v
)
103 if (lua_isstring(l
, LI_KEY
) && lua_isnumber(l
, LI_VALUE
))
105 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
107 *v
= lua_tonumber(l
, LI_VALUE
);
114 gboolean
l_chk_assign_n(lua_State
*l
, const gchar
*k
, gdouble
*v
)
117 if (l_chk_n(l
, k
, &n
) == TRUE
)
125 gboolean
l_chk_b(lua_State
*l
, const gchar
*w
, gboolean
*v
)
127 if (lua_isstring(l
, LI_KEY
) && lua_isboolean(l
, LI_VALUE
))
129 if (g_strcmp0(lua_tostring(l
, LI_KEY
), w
) == 0)
131 *v
= lua_toboolean(l
, LI_VALUE
);
138 gboolean
l_chk_assign_b(lua_State
*l
, const gchar
*k
, gboolean
*v
)
141 if (l_chk_b(l
, k
, &b
) == TRUE
)
149 /* vim: set ts=2 sw=2 tw=72 expandtab: */