Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Question

I'm sure this is probably something really simple and I'm just dumb lol

How do you add launch options to a program, like how cp, mv and rm have?

 

I need to do something like this:

if option then

print("Hello, World!")

else do end

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 1

Just add this to your code:

local shell = require "shell"
local args, ops = shell.parse(...)

You can read more on the shell.parse function here.

But basically, options following a single '-' is split into single characters (that means -test sets the options t, e, s, t and NOT a single option called "test). To have an option name with more characters, use the double '--' following the name (--test will set a single option called "test")

So, if you have a file test.lua, you could add the following (of cause also adding the 2 lines above as well)

if args.o then
  -- do some stuff
end
if args.p then
  -- do something else
end
if help then
  -- print some help message
end

and then call it like: ' test.lua -op --help'.

Share this post


Link to post
Share on other sites
  • 0

im talking about launch options, like typing test.lua and hitting enter to get a single "Hello, World!" but running test.lua -option1 to make it send multiple

I want to be able to add a check for a specific suffix like "-constant" to make the program do something differently than if there was no suffix

Share this post


Link to post
Share on other sites
  • -1

don't know if i understand that right,

 

 

if variable == something then
	print ("hello world")
end

or maybe:

if event == "key_up" then
	if keynumber == 28 then print ("Enter") end
    if keynumber == 200 then print ("Arrow up") end
end

or maybe:

if event == "key_up" then
	if keynumber == 28 then print ("ENTER") end
	elseif keynumber == 200 then print ("Arrow up")
end

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.