r/lua • u/RiverBard • Nov 26 '25
Discussion Working with arbitrary numbers of args, emulating Python's slice?
This has come up as I've been working with the language and it hasn't been a problem yet, but I could see it being an issue. I think the easiest way to explain my question is to give an example:
# Print the given args, starting with the third and continuing through any number of given args
If I run this with runfile(args='a b c d e'), it will print:
b
c
d
e
This functionality with slices is really handy when you want to deal with an arbitrary number of arguments in a script.
In Lua, I've been working with varargs a bit, but my understanding of them is limited. Particularly, how you could go from a table of given arguments (the built-in arg table) to a vararg to give to a function, starting at a given index? Or maybe this isn't a relevant problem when working with Lua?
5
u/didntplaymysummercar Nov 26 '25
Use
table.unpack?1
u/AutoModerator Nov 26 '25
Hi! Your code block was formatted using triple backticks in Reddit's Markdown mode, which unfortunately does not display properly for users viewing via old.reddit.com and some third-party readers. This means your code will look mangled for those users, but it's easy to fix. If you edit your comment, choose "Switch to fancy pants editor", and click "Save edits" it should automatically convert the code block into Reddit's original four-spaces code block format for you.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
0
u/[deleted] Nov 28 '25
[deleted] — view deleted comment