Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function with variadic parameters in script. #255

Open
khchen opened this issue Jun 19, 2022 · 2 comments
Open

Function with variadic parameters in script. #255

khchen opened this issue Jun 19, 2022 · 2 comments
Labels
TODO It hasn't implemented yet.

Comments

@khchen
Copy link

khchen commented Jun 19, 2022

Native function can have variadic parameters by using pkGetArgc.
But it seems no way to have this ability it in script. Am I wrong?

@ThakeeNathees
Copy link
Owner

Yeah, at the moment it's not supported, thanks for the suggestion, I should definitely add this to the todo list.

@ThakeeNathees ThakeeNathees added the TODO It hasn't implemented yet. label Jun 21, 2022
@khchen
Copy link
Author

khchen commented Jul 22, 2022

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO It hasn't implemented yet.
Projects
None yet
Development

No branches or pull requests

2 participants