From 1c8f59fabaae265f1f6a031c22f57b0169d71006 Mon Sep 17 00:00:00 2001 From: dormando Date: Wed, 30 Oct 2024 11:44:43 -0700 Subject: [PATCH] proxy: make mutator user args start at 1 not 2 We already ++'ed the arg internally to skip "self" from the OO call format. mutator is always called as mut(dest, args) so 1 would be the "first user argument" --- proxy_mutator.c | 7 ++++--- t/proxymut.lua | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/proxy_mutator.c b/proxy_mutator.c index 6ee66c2d7..894f01732 100644 --- a/proxy_mutator.c +++ b/proxy_mutator.c @@ -140,8 +140,8 @@ static void _mut_check_idx(lua_State *L, int tidx) { if (!isnum) { proxy_lua_ferror(L, "mutator step %d: must provide 'idx' argument as an integer", tidx); } - if (i < 2) { - proxy_lua_ferror(L, "mutator step %d: 'idx' argument must be greater than 1", tidx); + if (i < 1) { + proxy_lua_ferror(L, "mutator step %d: 'idx' argument must be greater than 0", tidx); } } else { proxy_lua_ferror(L, "mutator step %d: must provide 'idx' argument", tidx); @@ -880,7 +880,8 @@ static int mcp_mutator_new(lua_State *L, enum mcp_mut_type type) { // around the much larger mcp_mut_entries at runtime. mut->steps[scount].n = mcp_mut_entries[st].n; mut->steps[scount].r = mcp_mut_entries[st].r; - mut->steps[scount].idx++; // actual args are "self, etc, etc" + // actual args are "self, dst, args". start user idx's at 3 + mut->steps[scount].idx += 2; } lua_pop(L, 1); // drop t or nil scount++; diff --git a/t/proxymut.lua b/t/proxymut.lua index 15bda6e05..b036aef22 100644 --- a/t/proxymut.lua +++ b/t/proxymut.lua @@ -40,14 +40,14 @@ function mcp_config_routes(p) -- res with value. local mut_mgresval = mcp.res_mutator_new( { t = "rescodeset", str = "VA" }, - { t = "valcopy", idx = 2, arg = "string" } + { t = "valcopy", idx = 1, arg = "string" } ) -- res with flags. local mut_mgresflag = mcp.res_mutator_new( { t = "rescodeset", str = "HD" }, { t = "flagset", flag = "t", val = "37" }, - { t = "flagcopy", flag = "O", idx = 2 } + { t = "flagcopy", flag = "O", idx = 1 } ) mgfg:ready({