seqlua
diff seqlua.c @ 15:a95fbd16473f
Removed unnecessary creation of closures for callable values (through __call)
| author | jbe |
|---|---|
| date | Wed Aug 20 06:33:18 2014 +0200 (2014-08-20) |
| parents | 03ed3361f332 |
| children | 040a0ca089c1 |
line diff
1.1 --- a/seqlua.c Wed Aug 20 06:08:03 2014 +0200 1.2 +++ b/seqlua.c Wed Aug 20 06:33:18 2014 +0200 1.3 @@ -1,13 +1,6 @@ 1.4 #include <lua.h> 1.5 #include <lauxlib.h> 1.6 1.7 -static int seqlua_aux_call(lua_State *L) { // TODO: avoid 1.8 - lua_pushvalue(L, lua_upvalueindex(1)); 1.9 - lua_pushvalue(L, lua_upvalueindex(2)); 1.10 - lua_call(L, 1, 1); 1.11 - return 1; 1.12 -} 1.13 - 1.14 static int seqlua_ipairsaux_raw(lua_State *L) { 1.15 lua_Integer i; 1.16 luaL_checktype(L, 1, LUA_TTABLE); 1.17 @@ -27,7 +20,7 @@ 1.18 } 1.19 1.20 static int seqlua_ipairsaux_func(lua_State *L) { 1.21 - luaL_checktype(L, 1, LUA_TFUNCTION); 1.22 + //luaL_checktype(L, 1, LUA_TFUNCTION); 1.23 lua_pushinteger(L, luaL_checkinteger(L, 2) + 1); 1.24 lua_insert(L, 1); 1.25 lua_settop(L, 2); 1.26 @@ -74,10 +67,7 @@ 1.27 } 1.28 lua_pushcfunction(L, seqlua_ipairsaux_func); 1.29 } else if (luaL_getmetafield(L, 1, "__call")) { 1.30 - if (lua_type(L, -1) != LUA_TFUNCTION) luaL_error(L, "__call is not a function"); 1.31 - lua_pushvalue(L, 1); 1.32 - lua_pushcclosure(L, seqlua_aux_call, 2); 1.33 - lua_replace(L, 1); 1.34 + lua_pop(L, 1); 1.35 goto seqlua_ipairs_function; 1.36 } else if (luaL_getmetafield(L, 1, "__index")) { 1.37 lua_pushcfunction(L, seqlua_ipairsaux_meta); 1.38 @@ -135,10 +125,7 @@ 1.39 lua_pushcclosure(L, seqlua_iteratoraux_triplet, 3); 1.40 } 1.41 } else if (luaL_getmetafield(L, 1, "__call")) { 1.42 - if (lua_type(L, -1) != LUA_TFUNCTION) luaL_error(L, "__call is not a function"); 1.43 - lua_pushvalue(L, 1); 1.44 - lua_pushcclosure(L, seqlua_aux_call, 2); 1.45 - lua_replace(L, 1); 1.46 + lua_pop(L, 1); 1.47 goto seqlua_iterator_function; 1.48 } else if (luaL_getmetafield(L, 1, "__index")) { 1.49 lua_pushvalue(L, 1);