Update NEWS for v0.9.4
[libquvi.git] / src / lua / util / exec_util_to_file_ext.c
blob6b9d4322bc6f279e89eae90fc605d4255c470cb3
1 /* libquvi
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/>.
21 #include "config.h"
23 #include <lauxlib.h>
24 #include <lualib.h>
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_http_metainfo_s.h"
31 #include "_quvi_net_s.h"
32 /* -- */
33 #include "lua/load_util_script.h"
35 static const gchar script_fname[]= "to_file_ext.lua";
36 static const gchar script_func[] = "to_file_ext";
38 QuviError l_exec_util_to_file_ext(_quvi_t q, const gchar *ct, GString *dst)
40 lua_State *l;
41 QuviError rc;
43 rc = l_load_util_script(q, script_fname, script_func);
44 if (rc != QUVI_OK)
45 return (rc);
47 l = q->handle.lua;
48 lua_pushstring(l, ct);
51 * 2=qargs,content-type [qargs: set in l_load_util_script]
52 * 1=returns a string
54 if (lua_pcall(l, 2, 1, 0))
56 g_string_assign(q->status.errmsg, lua_tostring(l, -1));
57 return (QUVI_ERROR_SCRIPT);
60 if (!lua_isstring(l, -1))
61 luaL_error(l, "%s: did not return a string", script_func);
63 g_string_assign(dst, lua_tostring(l,-1));
64 lua_pop(l, 1);
66 return (QUVI_OK);
69 /* vim: set ts=2 sw=2 tw=72 expandtab: */