@@ -12,41 +12,6 @@ namespace async_postgres::lua {
12
12
return 0 ;
13
13
}
14
14
15
- lua_protected_fn (__index) {
16
- auto state = lua_connection_state ();
17
-
18
- state->lua_table .Push ();
19
- lua->Push (2 );
20
- lua->GetTable (-2 );
21
- if (!lua->IsType (-1 , GLua::Type::Nil)) {
22
- return 1 ;
23
- }
24
-
25
- // is it alright if I don't pop previous stack values?
26
-
27
- lua->PushMetaTable (async_postgres::connection_meta);
28
- lua->Push (2 );
29
- lua->GetTable (-2 );
30
-
31
- return 1 ;
32
- }
33
-
34
- lua_protected_fn (__newindex) {
35
- auto state = lua_connection_state ();
36
-
37
- state->lua_table .Push ();
38
- lua->Push (2 );
39
- lua->Push (3 );
40
- lua->SetTable (-3 );
41
-
42
- auto key = get_string (lua, 2 );
43
- if (key == " on_notify" ) {
44
- state->receive_notifications = !lua->IsType (3 , GLua::Type::Nil);
45
- }
46
-
47
- return 1 ;
48
- }
49
-
50
15
lua_protected_fn (loop) {
51
16
async_postgres::process_pending_connections (lua);
52
17
@@ -126,6 +91,16 @@ namespace async_postgres::lua {
126
91
127
92
return 0 ;
128
93
}
94
+
95
+ lua_protected_fn (setNotifyCallback) {
96
+ lua->CheckType (1 , async_postgres::connection_meta);
97
+ lua->CheckType (2 , GLua::Type::Function);
98
+
99
+ auto state = lua_connection_state ();
100
+ state->on_notify = GLua::AutoReference (lua, 2 );
101
+
102
+ return 0 ;
103
+ }
129
104
} // namespace async_postgres::lua
130
105
131
106
#define register_lua_fn (name ) \
@@ -135,12 +110,14 @@ namespace async_postgres::lua {
135
110
void register_connection_mt(GLua::ILuaInterface* lua) {
136
111
async_postgres::connection_meta = lua->CreateMetaTable (" PGconn" );
137
112
138
- register_lua_fn (__index);
139
- register_lua_fn (__newindex);
113
+ lua->Push (-1 );
114
+ lua->SetField (-2 , " __index" );
115
+
140
116
register_lua_fn (__gc);
141
117
register_lua_fn (query);
142
118
register_lua_fn (queryParams);
143
119
register_lua_fn (reset);
120
+ register_lua_fn (setNotifyCallback);
144
121
145
122
async_postgres::register_misc_connection_functions (lua);
146
123
0 commit comments