Skip to content

Commit

Permalink
proxy: make mutator user args start at 1 not 2
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
dormando committed Oct 30, 2024
1 parent b038067 commit 1c8f59f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions proxy_mutator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++;
Expand Down
4 changes: 2 additions & 2 deletions t/proxymut.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 1c8f59f

Please sign in to comment.