1
1
#include < GarrysMod/Lua/Interface.h>
2
2
3
- #include " pgsqloo .hpp"
3
+ #include " async_postgres .hpp"
4
4
5
- int pgsqloo ::connection_meta = 0 ;
5
+ int async_postgres ::connection_meta = 0 ;
6
6
7
- #define lua_connection_state () \
8
- lua->GetUserType<pgsqloo::Connection>(1 , pgsqloo::connection_meta)
7
+ #define lua_connection_state () \
8
+ lua->GetUserType<async_postgres::Connection>( \
9
+ 1 , async_postgres::connection_meta)
9
10
10
11
lua_protected_fn (gc_connection) {
11
12
delete lua_connection_state ();
12
13
return 0 ;
13
14
}
14
15
15
- pgsqloo ::Connection::~Connection () {
16
+ async_postgres ::Connection::~Connection () {
16
17
// remove connection from global list
17
18
// so event loop doesn't try to process it
18
- pgsqloo::connections.erase (std::find (pgsqloo::connections.begin (),
19
- pgsqloo::connections.end (), this ));
19
+ async_postgres::connections.erase (
20
+ std::find (async_postgres::connections.begin (),
21
+ async_postgres::connections.end (), this ));
20
22
}
21
23
22
24
lua_protected_fn (index_connection) {
@@ -31,7 +33,7 @@ lua_protected_fn(index_connection) {
31
33
32
34
// is it alright if I don't pop previous stack values?
33
35
34
- lua->PushMetaTable (pgsqloo ::connection_meta);
36
+ lua->PushMetaTable (async_postgres ::connection_meta);
35
37
lua->Push (2 );
36
38
lua->GetTable (-2 );
37
39
@@ -172,11 +174,11 @@ lua_protected_fn(newindex_connection) {
172
174
// }
173
175
174
176
lua_protected_fn (loop) {
175
- pgsqloo ::process_pending_connections (lua);
177
+ async_postgres ::process_pending_connections (lua);
176
178
177
- for (auto state : pgsqloo ::connections) {
178
- pgsqloo ::process_notifications (lua, state);
179
- pgsqloo ::process_queries (lua, state);
179
+ for (auto state : async_postgres ::connections) {
180
+ async_postgres ::process_notifications (lua, state);
181
+ async_postgres ::process_queries (lua, state);
180
182
}
181
183
182
184
return 0 ;
@@ -189,20 +191,20 @@ lua_protected_fn(connect) {
189
191
auto url = lua->GetString (1 );
190
192
GLua::AutoReference callback (lua, 2 );
191
193
192
- pgsqloo ::connect (lua, url, std::move (callback));
194
+ async_postgres ::connect (lua, url, std::move (callback));
193
195
194
196
return 0 ;
195
197
}
196
198
197
199
lua_protected_fn (query) {
198
- lua->CheckType (1 , pgsqloo ::connection_meta);
200
+ lua->CheckType (1 , async_postgres ::connection_meta);
199
201
lua->CheckType (2 , GLua::Type::String);
200
202
lua->CheckType (3 , GLua::Type::Function);
201
203
202
204
auto state = lua_connection_state ();
203
205
204
- pgsqloo ::SimpleCommand command = {lua->GetString (2 )};
205
- pgsqloo ::Query query = {std::move (command)};
206
+ async_postgres ::SimpleCommand command = {lua->GetString (2 )};
207
+ async_postgres ::Query query = {std::move (command)};
206
208
if (!lua->IsType (3 , GLua::Type::Nil)) {
207
209
query.callback = GLua::AutoReference (lua, 3 );
208
210
}
@@ -232,7 +234,7 @@ lua_protected_fn(query) {
232
234
// }
233
235
234
236
inline void register_connection_mt (GLua::ILuaInterface* lua) {
235
- pgsqloo ::connection_meta = lua->CreateMetaTable (" PGconn" );
237
+ async_postgres ::connection_meta = lua->CreateMetaTable (" PGconn" );
236
238
237
239
lua->PushCFunction (index_connection);
238
240
lua->SetField (-2 , " __index" );
@@ -255,14 +257,14 @@ inline void make_global_table(GLua::ILuaInterface* lua) {
255
257
lua->PushCFunction (connect);
256
258
lua->SetField (-2 , " connect" );
257
259
258
- lua->SetField (GLua::INDEX_GLOBAL, " pg " );
260
+ lua->SetField (GLua::INDEX_GLOBAL, " async_postgres " );
259
261
}
260
262
261
263
inline void register_loop_hook (GLua::ILuaInterface* lua) {
262
264
lua->GetField (GLua::INDEX_GLOBAL, " hook" );
263
265
lua->GetField (-1 , " Add" );
264
266
lua->PushString (" Think" );
265
- lua->PushString (" pg_loop " );
267
+ lua->PushString (" async_postgres_loop " );
266
268
lua->PushCFunction (loop);
267
269
lua->Call (3 , 0 );
268
270
lua->Pop ();
0 commit comments