Jump to content




how to do my logic?



  • You cannot reply to this topic
23 replies to this topic

#1 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 30 May 2014 - 03:12 PM

Hello guys! Can you help me make this logic? please :)

This is my logic..

apt-get add-repo http://www.example.com/packages/

apt-get add-repo http://www.example2.com/packages/


It sets all the link in lines..
This is will happen.

http://www.example.com --> Line 1 of config.cfg
http://www.example2.com --> Line 2 of config.cfg
~~~~Another Logic~~~~~

This is my another logic:

apt-get install example
apt-get install example2

This will happen if it runs the code:
apt-get install example <--- config.cfg and finds the app from the repos.
apt-get install example2 <--- dis-same as above.

~~~~Another Logic~~~

making a folder.

test.lua:
local sFile = args[1]

test.lua testfolder

and then the testfolder will go to /tmp/testfolder

Edited by IsaacTBeast, 30 May 2014 - 03:19 PM.


#2 apemanzilla

  • Members
  • 1,421 posts

Posted 30 May 2014 - 03:32 PM

...what are you trying to do, exactly?

#3 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 30 May 2014 - 04:31 PM

View Postapemanzilla, on 30 May 2014 - 03:32 PM, said:

...what are you trying to do, exactly?

I am trying to make a package manager and remake apt-get from debian to ComputerCraft but this is for my program that I am making now :)

#4 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 30 May 2014 - 05:02 PM

This is what I do so far :)

local args = { ... }
local internet = {}
local installapplic = "/etc/applications"
local root = "/"
local function save(data,file)
		local file = shell.resolve(file)
		if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
				if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
				fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
		end
		local f = fs.open(file,"w")
		f.write(data)
		f.close()
end

local function download(url, file)
		save(http.get(url).readAll(),file)
end
function printUsage()
print("Usage: \n islx-app update --updates the config file. \n islx-app oldconfig --downloads the oldconfig. \n islx-app add-repo --to add your repo.")
end
if #args < 1 then
printUsage()
end
local sCommand = args[1]
local sAppfname = args[2]
local repolink = args[2]
if sCommand == "update" then
if fs.isDir("/tmp") then
  local fileH = http.get("https://raw.githubusercontent.com/iansapelino/islxcc/master/helloworld.lua")
  write(fileH.readAll())
  fileH.close()
  sleep(0.5)
  fs.delete("/tmp")
else
  fs.makeDir("/tmp")
  local fileH = http.get("https://raw.githubusercontent.com/iansapelino/islxcc/master/helloworld.lua")
  write(fileH.readAll())
  fileH.close()
  sleep(0.5)
  fs.delete("/tmp")
  end
end
if sCommand == "oldconfig" then
if fs.isDir("/etc") then
  if fs.exists("/etc/islxcc/islxcc.icfg") then
   fs.delete("/etc/islxcc/islxcc.icfg")
	  term.clear()
	  term.setCursorPos(1,1)
	  print("Downloading the Old Config for the packages..")
	  sleep(0.5)
	  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
  else
   term.clear()
	  term.setCursorPos(1,1)
	  print("Downloading the Old Config for the packages..")
	  sleep(0.5)
	  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
  end
else
  fs.makeDir("/etc")
  fs.makeDir("/etc/islxcc/")
  term.clear()
  term.setCursorPos(1,1)
  print("Downloading the Old Config for the packages..")
  sleep(0.5)
  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
end
end
if sCommand == "add-repo" then
   fs.makeDir( "/etc/"..repolink )
end

Edited by IsaacTBeast, 30 May 2014 - 05:03 PM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 May 2014 - 07:10 AM

At a glance, it looks like you've got an understanding of reading/writing files, creating directories and getting execution parameters already - I'm a little confused as to where exactly you're getting stuck?

#6 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 31 May 2014 - 08:01 AM

Can you guys help me?? I get an error called Unexpected String from number 91.

Heres my code.

local args = { ... }
local internet = {}
local installapplic = "/etc/applications"
local root = "/"
local etc = "/etc/applications/app"
--Credits to ApeManzilla
local function save(data,file)
	    local file = shell.resolve(file)
	    if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
			    if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
			    fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
	    end
	    local f = fs.open(file,"w")
	    f.write(data)
	    f.close()
end
--Credits to ApeManzilla
local function download(url, file)
	    save(http.get(url).readAll(),file)
end
--Credits to me.. xD
function printUsage()
print("Usage: \n islx-app update --updates the config file. \n islx-app oldconfig --downloads the oldconfig. \n islx-app add-repo --to add your repo.")
end
if #args < 1 then
printUsage()
end
--Main. This is what I create :)/>
local sCommand = args[1]
local sAppfname = args[2]
local repolink = args[2]
if sCommand == "update" then
if fs.isDir("/tmp") then
  local fileH = http.get("https://raw.githubusercontent.com/iansapelino/islxcc/master/helloworld.lua")
  write(fileH.readAll())
  fileH.close()
  sleep(0.5)
  fs.delete("/tmp")
else
  fs.makeDir("/tmp")
  local fileH = http.get("https://raw.githubusercontent.com/iansapelino/islxcc/master/helloworld.lua")
  write(fileH.readAll())
  fileH.close()
  sleep(0.5)
  fs.delete("/tmp")
  end
end
if sCommand == "oldconfig" then
if fs.isDir("/etc") then
  if fs.exists("/etc/islxcc/islxcc.icfg") then
   fs.delete("/etc/islxcc/islxcc.icfg")
	  term.clear()
	  term.setCursorPos(1,1)
	  print("Downloading the Old Config for the packages..")
	  sleep(0.5)
	  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
  else
   term.clear()
	  term.setCursorPos(1,1)
	  print("Downloading the Old Config for the packages..")
	  sleep(0.5)
	  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
  end
else
  fs.makeDir("/etc")
  fs.makeDir("/etc/islxcc/")
  term.clear()
  term.setCursorPos(1,1)
  print("Downloading the Old Config for the packages..")
  sleep(0.5)
  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
end
end
if sCommand == "add-repo" then
if fs.exists(tostring(repolink)) then
  fs.makeDir(tostring(repolink))
	 fs.copy(tostring(repolink), "etc/"..args[2])
	 fs.delete(tostring(repolink))
else
  fs.makeDir(tostring(repolink))
	 fs.copy(tostring(repolink), "etc/"..args[2])
	 fs.delete(tostring(repolink))
end
end
if sCommand == "install" then
download("https://raw.githubusercontent.com/iansapelino/islxcc/master/Programs/"..args[2], ..args[4])
end


#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 31 May 2014 - 10:23 AM

Threads merged. Please stick to one topic for all questions about a given piece of code.

#8 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 31 May 2014 - 10:36 AM

View PostBomb Bloke, on 31 May 2014 - 07:10 AM, said:

At a glance, it looks like you've got an understanding of reading/writing files, creating directories and getting execution parameters already - I'm a little confused as to where exactly you're getting stuck?

This is the one......... I am stuck at downloading install using a argument..

View PostIsaacTBeast, on 31 May 2014 - 08:01 AM, said:

Can you guys help me?? I get an error called Unexpected String from number 91.

Heres my code.

local args = { ... }
local internet = {}
local installapplic = "/etc/applications"
local root = "/"
local etc = "/etc/applications/app"
--Credits to ApeManzilla
local function save(data,file)
		local file = shell.resolve(file)
		if not (fs.exists(string.sub(file,1,#file - #fs.getName(file))) and fs.isDir(string.sub(file,1,#file - #fs.getName(file)))) then
				if fs.exists(string.sub(file,1,#file - #fs.getName(file))) then fs.delete(string.sub(file,1,#file - #fs.getName(file))) end
				fs.makeDir(string.sub(file,1,#file - #fs.getName(file)))
		end
		local f = fs.open(file,"w")
		f.write(data)
		f.close()
end
--Credits to ApeManzilla
local function download(url, file)
		save(http.get(url).readAll(),file)
end
--Credits to me.. xD
function printUsage()
print("Usage: \n islx-app update --updates the config file. \n islx-app oldconfig --downloads the oldconfig. \n islx-app add-repo --to add your repo.")
end
if #args < 1 then
printUsage()
end
--Main. This is what I create :)/>/>/>
local sCommand = args[1]
local sAppfname = args[2]
local repolink = args[2]
if sCommand == "update" then
if fs.isDir("/tmp") then
  local fileH = http.get("https://raw.githubusercontent.com/iansapelino/islxcc/master/helloworld.lua")
  write(fileH.readAll())
  fileH.close()
  sleep(0.5)
  fs.delete("/tmp")
else
  fs.makeDir("/tmp")
  local fileH = http.get("https://raw.githubusercontent.com/iansapelino/islxcc/master/helloworld.lua")
  write(fileH.readAll())
  fileH.close()
  sleep(0.5)
  fs.delete("/tmp")
  end
end
if sCommand == "oldconfig" then
if fs.isDir("/etc") then
  if fs.exists("/etc/islxcc/islxcc.icfg") then
   fs.delete("/etc/islxcc/islxcc.icfg")
	  term.clear()
	  term.setCursorPos(1,1)
	  print("Downloading the Old Config for the packages..")
	  sleep(0.5)
	  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
  else
   term.clear()
	  term.setCursorPos(1,1)
	  print("Downloading the Old Config for the packages..")
	  sleep(0.5)
	  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
  end
else
  fs.makeDir("/etc")
  fs.makeDir("/etc/islxcc/")
  term.clear()
  term.setCursorPos(1,1)
  print("Downloading the Old Config for the packages..")
  sleep(0.5)
  download("https://raw.githubusercontent.com/iansapelino/islxcc/master/islxcc.icfg", "/etc/islxcc/islxcc.icfg")
end
end
if sCommand == "add-repo" then
if fs.exists(tostring(repolink)) then
  fs.makeDir(tostring(repolink))
	 fs.copy(tostring(repolink), "etc/"..args[2])
	 fs.delete(tostring(repolink))
else
  fs.makeDir(tostring(repolink))
	 fs.copy(tostring(repolink), "etc/"..args[2])
	 fs.delete(tostring(repolink))
end
end
if sCommand == "install" then
download("https://raw.githubusercontent.com/iansapelino/islxcc/master/Programs/"..args[2], ..args[2])
end

This is the code.. :)

I got stuck at islx-app install because it says that unexpected string at number line 91.

Edited by IsaacTBeast, 31 May 2014 - 10:36 AM.


#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 May 2014 - 11:11 AM

Line 91 in what file? The code you've posted doesn't have that many lines. What's the full error?

#10 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 31 May 2014 - 11:53 AM

Maybe post it on Pastebin... Then we can see syntax and line numbers.

#11 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 31 May 2014 - 12:07 PM

Here you go http://pastebin.com/d8KczPYV

#12 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 31 May 2014 - 12:47 PM

any replies?

#13 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 May 2014 - 01:17 PM

Line 91 is blank in that version. Again, please provide the full error.

#14 IsaacTBeast

  • Members
  • 86 posts
  • LocationI 'm inside your brian

Posted 31 May 2014 - 01:58 PM

View PostBomb Bloke, on 31 May 2014 - 01:17 PM, said:

Line 91 is blank in that version. Again, please provide the full error.

Thanks but I think I fixed it now I changed it.. and look at the link again..

But the error
line 92 attempt to index ? (a nil value)

Edited by IsaacTBeast, 31 May 2014 - 02:06 PM.


#15 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 31 May 2014 - 06:00 PM

View PostIsaacTBeast, on 31 May 2014 - 01:58 PM, said:

View PostBomb Bloke, on 31 May 2014 - 01:17 PM, said:

Line 91 is blank in that version. Again, please provide the full error.

Thanks but I think I fixed it now I changed it.. and look at the link again..

But the error
line 92 attempt to index ? (a nil value)

It appears that args[2] seems to be a nil value. In other words: args[2] has no value.

#16 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 31 May 2014 - 06:33 PM

I noticed you only do a sanity check for 1 argument but then require more than one. Is it possible you are not passing the second argument, thus resulting in args[2] being nil?

EDIT: ninja'd by GamerNebulae

Edited by Dog, 31 May 2014 - 09:14 PM.


#17 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 31 May 2014 - 08:05 PM

View PostDog, on 31 May 2014 - 06:33 PM, said:

I noticed you only do a sanity check for 1 argument but then require more than one. Is it possible you are not passing the second argument, thus resulting in args[2] being nil? I also noticed that you're calling 'http.get' with a write. Should the 'get' be 'post'? (I'm not sure, apologies if I'm misleading you here).

As I tried to clarify above your post, lol. What I and Dog are trying to say is this.
--If you typed this in your Computer:
<program title> variable1 variable2
In your program, variable1 is args[1] and variable2 is args[2]. If you are not planning to add more commands, then you should change the code so it checks if args[1] is "add-repo" or "oldconfig". Something like this:
if args[1] == "oldconfig" then
  sCommand = args[1]
  <actions>
elseif args[1] == "add-repo" then
  sCommand = args[1]
  <actions>
end


#18 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 31 May 2014 - 09:19 PM

View PostGamerNebulae, on 31 May 2014 - 08:05 PM, said:

As I tried to clarify above your post, lol. What I and Dog are trying to say is this.
--If you typed this in your Computer:
<program title=""> variable1 variable2
In your program, variable1 is args[1] and variable2 is args[2]. If you are not planning to add more commands, then you should change the code so it checks if args[1] is "add-repo" or "oldconfig". Something like this:
if args[1] == "oldconfig" then
  sCommand = args[1]
  <actions>
elseif args[1] == "add-repo" then
  sCommand = args[1]
  <actions>
end

That's not what I was trying to say. Allow me to clarify a bit...

Your clarification (second post) mentions args[2], but it doesn't really address or explain the nil value of args[2]. My question was whether IsaacTBeast is even passing a second argument to the program. Currently the program only checks to see if the first argument was passed, but is complaining that the second argument is nil. There's no sanity check for the second argument, so if one is never provided it will be nil from the get-go.

Looking at the code, I can only see one reason why args[2] would be nil (thus causing the error IsaacTBeast is encountering): The second argument isn't being passed to the program.

No amount of tinkering with args[1] is going to fix that.

My theory can easily be verified by changing line 27 from
if #args < 1 then

to
if #args < 2 then

If the second argument isn't being passed, the usage screen will be displayed instead of the program continuing.

IsaacTBeast - would you please post the exact command you are using to launch the program and (for good measure) verify that the file actually exists on Github.

Edited by Dog, 31 May 2014 - 09:23 PM.


#19 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 31 May 2014 - 09:48 PM

View PostDog, on 31 May 2014 - 09:19 PM, said:

View PostGamerNebulae, on 31 May 2014 - 08:05 PM, said:

As I tried to clarify above your post, lol. What I and Dog are trying to say is this.
--If you typed this in your Computer:
<program title=""> variable1 variable2
In your program, variable1 is args[1] and variable2 is args[2]. If you are not planning to add more commands, then you should change the code so it checks if args[1] is "add-repo" or "oldconfig". Something like this:
if args[1] == "oldconfig" then
  sCommand = args[1]
  <actions>
elseif args[1] == "add-repo" then
  sCommand = args[1]
  <actions>
end

That's not what I was trying to say. Allow me to clarify a bit...

Your clarification (second post) mentions args[2], but it doesn't really address or explain the nil value of args[2]. My question was whether IsaacTBeast is even passing a second argument to the program. Currently the program only checks to see if the first argument was passed, but is complaining that the second argument is nil. There's no sanity check for the second argument, so if one is never provided it will be nil from the get-go.

Looking at the code, I can only see one reason why args[2] would be nil (thus causing the error IsaacTBeast is encountering): The second argument isn't being passed to the program.

No amount of tinkering with args[1] is going to fix that.

My theory can easily be verified by changing line 27 from
if #args < 1 then

to
if #args < 2 then

If the second argument isn't being passed, the usage screen will be displayed instead of the program continuing.

IsaacTBeast - would you please post the exact command you are using to launch the program and (for good measure) verify that the file actually exists on Github.

Yeah, that was sorta my explanation, but yours is way better... ;)

#20 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 June 2014 - 02:32 AM

92:

app.write(http.get( "https://raw.githubusercontent.com/iansapelino/islxcc/master/Programs/"..args[2] ).readAll())

You guys are misreading the error - an "attempt to index nil" doesn't mean that something like args[2] is nil, it means that something like args is nil. That can't be true, so presumably it doesn't like the attempt to index "readAll" from within "http.get()". Or "get" from within "http".

This could mean the http API isn't enabled, or that there's some other problem with the attempt to get the website handle.

It's a bad idea to do the "get" and the "read" on one line anyway. That means you don't retain the handle, which you should be closing after the read (impossible if you didn't keep the pointer):

local webHandle = http.get( "https://raw.githubusercontent.com/iansapelino/islxcc/master/Programs/"..args[2] )
app.write(webHandle.readAll())
webHandle.close()

Though I'm still suspecting the error is happening within some API this script is calling - I'd expect the full error to include information about the name of the file within which the error occurred.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users