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/>.
23 #include <glib/gi18n-lib.h>
30 #include "_quvi_script_s.h"
33 #include "lua/setfield.h"
35 static GSList
*_match_util_script(_quvi_t q
, const gchar
*w
)
42 curr
= q
->scripts
.util
;
45 qs
= (_quvi_script_t
) curr
->data
;
46 s
= g_path_get_basename(qs
->fpath
->str
);
47 r
= (g_strcmp0(s
, w
) == 0) ? TRUE
:FALSE
;
55 curr
= g_slist_next(curr
);
60 QuviError
l_load_util_script(_quvi_t q
, const gchar
*script_fname
,
61 const gchar
*script_func
)
67 s
= _match_util_script(q
, script_fname
);
72 luaL_error(l
, _("Could not the find utility script `%s' in the path"),
77 lua_getglobal(l
, script_func
);
79 qs
= (_quvi_script_t
) s
->data
;
81 if (luaL_dofile(l
, qs
->fpath
->str
))
82 luaL_error(l
, "%s", lua_tostring(l
, -1));
84 lua_getglobal(l
, script_func
);
86 if (!lua_isfunction(l
, -1))
88 luaL_error(l
, "%s: the function `%s' was not found",
89 qs
->fpath
->str
, script_func
);
93 l_set_reg_userdata(l
, USERDATA_QUVI_T
, (gpointer
) q
);
98 /* vim: set ts=2 sw=2 tw=72 expandtab: */