Find and share HowTos to various installations / configurations!
CyaNn
Posts: 97 Joined: Tue Nov 23, 2010 9:48 am
Function pass va_list to another function
Post
by CyaNn » Sun Oct 18, 2020 6:03 am
Hello all !
A question is really desapointing me in CTRL / CTRL++ from a while.
Here it is ! I want to pass arbitrary number of parameter from a function to another (like javascript REST parameters / SPREAD operator).
Here is my exampe :
Code: Select all
class MyClass {
public caller() {
callIt("test1", "test2");
}
private callIt(... /* pass this */) {
callFunction(this.called, ... /* to this */);
}
private called(string param1, string param2) {
DebugTN("WORKS !!!!", param1, param2);
}
}
A really apreciate if someone have a solution to do that.
Regards.
Yann
CyaNn
Posts: 97 Joined: Tue Nov 23, 2010 9:48 am
Re: Function pass va_list to another function
Post
by CyaNn » Sun Oct 18, 2020 6:11 am
Here is the javascript example
Code: Select all
function caller() {
callIt("param 1", "param 2");
}
function callIt(... params) {
called(... params);
}
function called(... params) {
console.log("Works !", params[0], params[1]);
}
caller();
See working it here :
https://jsfiddle.net/CyaNn/rzayd4uo/3/
gschijndel
Posts: 376 Joined: Tue Jan 15, 2019 3:12 pm
Re: Function pass va_list to another function
Post
by gschijndel » Mon Oct 19, 2020 3:39 pm
I see no reason why it should not work. Did you try to pass the va_list to another function?
Code: Select all
private callIt(... /* pass this */)
{
va_list args;
va_start(args);
callFunction(this.called, args);
va_end(args);
}
private called(...)
{
va_list args;
int argc = va_start(args);
Debug(getCurrentTime(), "WORKS !!!!");
for (int i = 1; i < argc; i++)
{
Debug(args[i]);
}
DebugN(args[argc]);
va_end(args);
}
CyaNn
Posts: 97 Joined: Tue Nov 23, 2010 9:48 am
Re: Function pass va_list to another function
Post
by CyaNn » Tue Oct 20, 2020 4:48 pm
Many thanks for the response.
I think the problem comme from the function "callfunction" of wincc api :
This does not works :
Code: Select all
class MyClass {
public caller() {
callIt("test1", "test2");
}
private callIt(...) {
va_list args;
va_start(args);
callFunction(this.called, args);
va_end(args);
}
private called(string param1, string param2) {
DebugTN("WORKS !!!!", param1, param2);
}
};