@@ -12,41 +12,6 @@ namespace async_postgres::lua {
1212 return 0 ;
1313 }
1414
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-
5015 lua_protected_fn (loop) {
5116 async_postgres::process_pending_connections (lua);
5217
@@ -126,6 +91,16 @@ namespace async_postgres::lua {
12691
12792 return 0 ;
12893 }
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+ }
129104} // namespace async_postgres::lua
130105
131106#define register_lua_fn (name ) \
@@ -135,12 +110,14 @@ namespace async_postgres::lua {
135110void register_connection_mt(GLua::ILuaInterface* lua) {
136111 async_postgres::connection_meta = lua->CreateMetaTable (" PGconn" );
137112
138- register_lua_fn (__index);
139- register_lua_fn (__newindex);
113+ lua->Push (-1 );
114+ lua->SetField (-2 , " __index" );
115+
140116 register_lua_fn (__gc);
141117 register_lua_fn (query);
142118 register_lua_fn (queryParams);
143119 register_lua_fn (reset);
120+ register_lua_fn (setNotifyCallback);
144121
145122 async_postgres::register_misc_connection_functions (lua);
146123
0 commit comments