pocketlang
pocketlang copied to clipboard
Function with variadic parameters in script.
Native function can have variadic parameters by using pkGetArgc. But it seems no way to have this ability it in script. Am I wrong?
Yeah, at the moment it's not supported, thanks for the suggestion, I should definitely add this to the todo list.
I can achieve similar behavior via callable object and native code in this branch.
I still have no idea how to implement in compiler and vm since the extra arguments must be discarded.
Example:
from types import Variadic
test = Variadic fn(arguments)
print(arguments)
end
test(1)
test(1, 2, 3)
class Foo is Variadic
def _init
self.msg = "hello"
end
def _test1(arguments)
print(self.msg, "test1", arguments)
end
def _test2(arguments)
print(self.msg, "test2", arguments)
end
end
f = Foo()
f.test1(1)
f.test2(1, 2, 3)
Output:
[1]
[1, 2, 3]
hello test1 [1]
hello test2 [1, 2, 3]