|
| 1 | + |
| 2 | + |
1 | 3 | #include "async_postgres.hpp"
|
2 | 4 |
|
3 | 5 | using namespace async_postgres;
|
@@ -195,3 +197,41 @@ void async_postgres::register_misc_connection_functions(
|
195 | 197 | register_lua_fn(escapeBytea);
|
196 | 198 | register_lua_fn(unescapeBytea);
|
197 | 199 | }
|
| 200 | + |
| 201 | +#define enum_value(name) {#name, name} |
| 202 | + |
| 203 | +void async_postgres::register_enums(GLua::ILuaInterface* lua) { |
| 204 | + using enum_array = std::vector<std::pair<const char*, int>>; |
| 205 | + |
| 206 | + std::vector<enum_array> enums = { |
| 207 | + { |
| 208 | + enum_value(CONNECTION_OK), |
| 209 | + enum_value(CONNECTION_BAD), |
| 210 | + }, |
| 211 | + { |
| 212 | + enum_value(PQTRANS_IDLE), |
| 213 | + enum_value(PQTRANS_ACTIVE), |
| 214 | + enum_value(PQTRANS_INTRANS), |
| 215 | + enum_value(PQTRANS_INERROR), |
| 216 | + enum_value(PQTRANS_UNKNOWN), |
| 217 | + }, |
| 218 | + { |
| 219 | + enum_value(PQERRORS_TERSE), |
| 220 | + enum_value(PQERRORS_DEFAULT), |
| 221 | + enum_value(PQERRORS_VERBOSE), |
| 222 | + enum_value(PQERRORS_SQLSTATE), |
| 223 | + }, |
| 224 | + { |
| 225 | + enum_value(PQSHOW_CONTEXT_NEVER), |
| 226 | + enum_value(PQSHOW_CONTEXT_ERRORS), |
| 227 | + enum_value(PQSHOW_CONTEXT_ALWAYS), |
| 228 | + }, |
| 229 | + }; |
| 230 | + |
| 231 | + for (const auto& e : enums) { |
| 232 | + for (const auto& [name, value] : e) { |
| 233 | + lua->PushNumber(value); |
| 234 | + lua->SetField(-2, name); |
| 235 | + } |
| 236 | + } |
| 237 | +} |
0 commit comments