]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | libloc - A library to determine the location of someone on the Internet | |
3 | ||
4 | Copyright (C) 2024 IPFire Development Team <info@ipfire.org> | |
5 | ||
6 | This library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
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 GNU | |
14 | Lesser General Public License for more details. | |
15 | */ | |
16 | ||
17 | #include <errno.h> | |
18 | #include <string.h> | |
19 | ||
20 | #include <lua.h> | |
21 | #include <lauxlib.h> | |
22 | #include <lualib.h> | |
23 | ||
24 | #include <libloc/libloc.h> | |
25 | ||
26 | #include "location.h" | |
27 | #include "database.h" | |
28 | ||
29 | struct loc_ctx* ctx = NULL; | |
30 | ||
31 | static int version(lua_State* L) { | |
32 | lua_pushstring(L, PACKAGE_VERSION); | |
33 | return 1; | |
34 | } | |
35 | ||
36 | static const struct luaL_Reg location_functions[] = { | |
37 | { "version", version }, | |
38 | { NULL, NULL }, | |
39 | }; | |
40 | ||
41 | int luaopen_location(lua_State* L) { | |
42 | int r; | |
43 | ||
44 | // Initialize the context | |
45 | r = loc_new(&ctx); | |
46 | if (r) | |
47 | return luaL_error(L, | |
48 | "Could not initialize location context: %s\n", strerror(errno)); | |
49 | ||
50 | // Register functions | |
51 | luaL_newlib(L, location_functions); | |
52 | ||
53 | // Register Database type | |
54 | register_database(L); | |
55 | ||
56 | lua_setfield(L, -2, "Database"); | |
57 | ||
58 | return 1; | |
59 | } |