tests: quvi: Sprinkle with quvi_ok calls
[libquvi.git] / src / lua / init.c
blobc76d13a2595b2c0ff958db56a18333650931bf16
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"
31 /* 'quvi' object functions for scripts, e.g. 'quvi.http.fetch' */
33 extern gint l_quvi_http_metainfo(lua_State*);
34 extern gint l_quvi_http_resolve(lua_State*);
35 extern gint l_quvi_http_cookie(lua_State*);
36 extern gint l_quvi_http_header(lua_State*);
37 extern gint l_quvi_http_fetch(lua_State*);
39 static const luaL_Reg quvi_reg_meth[] =
41 {NULL, NULL}
44 static const luaL_Reg quvi_http_reg_meth[] =
46 {"metainfo", l_quvi_http_metainfo},
47 {"resolve", l_quvi_http_resolve},
48 {"cookie", l_quvi_http_cookie},
49 {"header", l_quvi_http_header},
50 {"fetch", l_quvi_http_fetch},
51 {NULL, NULL}
54 extern gint l_quvi_crypto_encrypt(lua_State*);
55 extern gint l_quvi_crypto_decrypt(lua_State*);
56 extern gint l_quvi_crypto_hash(lua_State*);
58 static const luaL_Reg quvi_crypto_reg_meth[] =
60 {"encrypt", l_quvi_crypto_encrypt},
61 {"decrypt", l_quvi_crypto_decrypt},
62 {"hash", l_quvi_crypto_hash},
63 {NULL, NULL}
66 extern gint l_quvi_base64_encode(lua_State*);
67 extern gint l_quvi_base64_decode(lua_State*);
69 static const luaL_Reg quvi_base64_reg_meth[] =
71 {"encode", l_quvi_base64_encode},
72 {"decode", l_quvi_base64_decode},
73 {NULL, NULL}
76 QuviError l_init(_quvi_t q)
78 q->handle.lua = (lua_State*) luaL_newstate();
79 if (q->handle.lua == NULL)
80 return (QUVI_ERROR_LUA_INIT);
82 luaL_openlibs(q->handle.lua);
83 luaL_register(q->handle.lua, "quvi", quvi_reg_meth);
84 luaL_register(q->handle.lua, "quvi.http", quvi_http_reg_meth);
85 luaL_register(q->handle.lua, "quvi.crypto", quvi_crypto_reg_meth);
86 luaL_register(q->handle.lua, "quvi.base64", quvi_base64_reg_meth);
88 return (QUVI_OK);
91 /* vim: set ts=2 sw=2 tw=72 expandtab: */