fix ForgeFunction argument handling and firstParamCondition - #403
Conversation
Daaisukidayo
commented
Aug 13, 2026
- Prevent function arguments from overwriting existing environment variables.
- Restore previous environment variable values after the function finishes.
- Preserve the first argument when using firstParamCondition.
|
The code I used to test the function arguments: $jsonLoad[number;0]
$jsonLoad[obj;{"number": 0}]
$env[number] // should return 0
$env[obj;number] // should return 0 value from the 'obj' json
$returnNum[1;2] // ForgeFunction should create environment variables 'number' and 'test', and then return 1, since it received this number
$env[number] // should return 0 after the fix, because we manually created the 'number' variable earlier. Before the fix, it returned 1, because the argument environment variable was overwriting the previously created 'number' variable
$env[obj;number] // should return 1 because we used $jsonSet inside the custom function
$env[num] // shouldn't return anything because the 'num' variable was created inside the custom function
$env[test] // shouldn't return anything. Before the fix, it returned '2' because ForgeFunction didn't "delete" the argument variables after executionThe custom function code: export default new ForgeFunction({
name: "returnNum",
params: [
{ name: "number", type: ArgType.Number},
{ name: "test", required: false},
],
code: `
$jsonLoad[num;1]
$jsonSet[obj;number;1]
$return[$env[number]]
`
}) |
|
The code i've used to test firstParamCondition fix: $test[true;0;1] // should return 'true, 0, 1'
$test[false;0;1] // shouldn't return anythingThe custom function code: export default new ForgeFunction({
name: "test",
firstParamCondition: true,
params: [
{ name: "test1" },
{ name: "test2" },
{ name: "test3" },
],
code: `
$return[$env[test1], $env[test2], $env[test3]]
`
}) |
Why should the custom function not execute at all when the condition is falsy? In my opinion, it would be more practical to let the first param return the resolved condition as boolean value which then can be used for custom statements and checks inside the code, instead of stopping function execution immediately. If this was the original implementation, I'd like to restructure this! |
I fixed only the part when the first param completely disappears if params: [
{
name: 'number',
type: "Number",
required: true,
},
],
firstParamCondition: true,The param
Yeah, this was the original implementation |
|
LGTM, thanks a lot for your contribution! 🙏 |