blockly-lua icon indicating copy to clipboard operation
blockly-lua copied to clipboard

[Suggestion] Varargs

Open theoriginalbit opened this issue 10 years ago • 2 comments

In Lua it is possible to have vararg functions, I'm sure you should know what they are as they're in multiple languages, I think blockly-lua having support would be good.

examples

local args = {...} -- getting all the runtime args of the program

local function foo(...) -- vararg function
  local args = {...} -- varargs of the function
  print(...) -- print is a vararg function it will concat all these together and output them
end

-- calling vararg functions is not a static amount
foo("bar")
foo("bar", "hello", "world")

theoriginalbit avatar Nov 05 '13 03:11 theoriginalbit

Support for calling vararg procedures would be easy. I'd use a "mutator", as shown for text create.

For creating vararg procedures, it would be much easier to just create procedures that take a list (table with keys of 1, 2, ...) as an argument. Doing things right would be hard, although you're welcome to take it on.

espertus avatar Nov 05 '13 04:11 espertus

Yeh I definitely don't think any of my suggestions are the easiest to implement... I just felt I'd add them all since I have more experience (just over 2 years now if I remember correctly) in ComputerCraft/Lua, as they can be very vital and/or useful parts of the language, and/or language syntax...

I may take a further look into this one once Uni is finished for the semester as well as #5

theoriginalbit avatar Nov 05 '13 04:11 theoriginalbit