Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Actually make the shadow tables work, and add a test to prove it.

  • Loading branch information...
commit 48d694142688b10cf0fc66d8713bb3b068626103 1 parent 9fb9107
Brian Maher authored
View
3  idle_lua_ev.c
@@ -31,9 +31,6 @@ static int create_idle_mt(lua_State *L) {
add_watcher_mt(L);
luaL_register(L, NULL, fns);
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
return 1;
}
View
3  io_lua_ev.c
@@ -31,9 +31,6 @@ static int create_io_mt(lua_State *L) {
add_watcher_mt(L);
luaL_register(L, NULL, fns);
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
return 1;
}
View
8 obj_lua_ev.c
@@ -99,13 +99,19 @@ static int obj_newindex(lua_State *L) {
* [-0, +1, ?]
*/
static int obj_index(lua_State *L) {
+ if ( lua_getmetatable(L, 1) ) {
+ lua_pushvalue(L, 2);
+ lua_gettable(L, -2);
+ if ( ! lua_isnil(L, -1) ) return 1;
+ lua_pop(L, 1);
+ }
lua_getfenv(L, 1);
lua_rawgeti(L, -1, WATCHER_SHADOW);
if ( lua_isnil(L, -1) ) return 1;
lua_pushvalue(L, 2);
- lua_gettable(L, -1);
+ lua_gettable(L, -2);
return 1;
}
View
3  signal_lua_ev.c
@@ -31,9 +31,6 @@ static int create_signal_mt(lua_State *L) {
add_watcher_mt(L);
luaL_register(L, NULL, fns);
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
return 1;
}
View
13 test/test_ev_idle.lua
@@ -64,5 +64,18 @@ function test_priority()
idle_daemon:stop(loop)
end
+function test_shadow_table()
+ local idle = ev.Idle.new(
+ function(loop, idle, revents)
+ idle:stop(loop)
+ ok(idle.user_data == "foo", 'shadow table works in callback')
+ end)
+ idle:start(loop)
+ idle.user_data = "foo"
+ ok(idle.user_data == "foo", 'shadow table works')
+ loop:loop()
+end
+
noleaks(test_basic, "test_basic")
noleaks(test_priority, "test_priority")
+noleaks(test_shadow_table, "test_shadow_table")
View
3  timer_lua_ev.c
@@ -33,9 +33,6 @@ static int create_timer_mt(lua_State *L) {
add_watcher_mt(L);
luaL_register(L, NULL, fns);
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__index");
-
return 1;
}
Please sign in to comment.
Something went wrong with that request. Please try again.