Permalink
Browse files

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

  • Loading branch information...
1 parent 9fb9107 commit 48d694142688b10cf0fc66d8713bb3b068626103 Brian Maher committed Sep 7, 2010
Showing with 20 additions and 13 deletions.
  1. +0 −3 idle_lua_ev.c
  2. +0 −3 io_lua_ev.c
  3. +7 −1 obj_lua_ev.c
  4. +0 −3 signal_lua_ev.c
  5. +13 −0 test/test_ev_idle.lua
  6. +0 −3 timer_lua_ev.c
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
}

0 comments on commit 48d6941

Please sign in to comment.