forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua-utils.hpp
More file actions
67 lines (55 loc) · 2.37 KB
/
Copy pathlua-utils.hpp
File metadata and controls
67 lines (55 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef OSM2PGSQL_LUA_UTILS_HPP
#define OSM2PGSQL_LUA_UTILS_HPP
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2021 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
// This file contains helper functions for talking to Lua. It is used from
// the flex output backend. All functions start with "luaX_".
extern "C"
{
#include <lua.h>
}
#include <cstdint>
#include <utility>
void luaX_set_context(lua_State *lua_state, void *ptr) noexcept;
void *luaX_get_context(lua_State *lua_state) noexcept;
void luaX_add_table_str(lua_State *lua_state, char const *key,
char const *value) noexcept;
void luaX_add_table_str(lua_State *lua_state, char const *key,
char const *value, std::size_t size) noexcept;
void luaX_add_table_int(lua_State *lua_state, char const *key,
int64_t value) noexcept;
void luaX_add_table_num(lua_State *lua_state, char const *key,
double value) noexcept;
void luaX_add_table_bool(lua_State *lua_state, char const *key,
bool value) noexcept;
void luaX_add_table_func(lua_State *lua_state, char const *key,
lua_CFunction func) noexcept;
template <typename COLLECTION, typename FUNC>
void luaX_add_table_array(lua_State *lua_state, char const *key,
COLLECTION const &collection, FUNC &&func)
{
lua_pushstring(lua_state, key);
lua_createtable(lua_state, (int)collection.size(), 0);
int n = 0;
for (auto const &member : collection) {
lua_pushinteger(lua_state, ++n);
std::forward<FUNC>(func)(member);
lua_rawset(lua_state, -3);
}
lua_rawset(lua_state, -3);
}
char const *luaX_get_table_string(lua_State *lua_state, char const *key,
int table_index, char const *error_msg);
char const *luaX_get_table_string(lua_State *lua_state, char const *key,
int table_index, char const *error_msg,
char const *default_value);
bool luaX_get_table_bool(lua_State *lua_state, char const *key, int table_index,
char const *error_msg, bool default_value);
int luaX_pcall(lua_State *lua_state, int narg, int nres);
#endif // OSM2PGSQL_LUA_UTILS_HPP