This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lua.is.the.best's profile picture

Check the whole drive for a file named "Newapi", and import it as an API

Started by Lua.is.the.best, 08 April 2014 - 01:00 AM
Lua.is.the.best #1
Posted 08 April 2014 - 03:00 AM
I couldn't do it the normal way.
I got:
File not found
testprg:2: attempt to index ? (a nil value)
Running dir:
Newapi testprg
The one underlined is the one I tried to load.
testprg:

os.loadAPI("Newapi")
Newapi.getInfo()
Newapi.getExtendedInfo()
--While loop constantly checking a number
while true do
wait(5)
Newapi.launchNumberGen(21,29,37,45,66,"Lucky!","Unlucky!")

I have all 3 defined (and launchNumberGen is supposed to have all those variables :o/>)
If you need to I would probably get the Newapi source code from its file :P/>
theoriginalbit #2
Posted 08 April 2014 - 03:36 AM
previously I had a similar problem which I solved by making a file system iterator.

Usage:

for path,file in fileSystemIter() do
  if file == "newapi" then
	os.loadAPI(path..file)
  end
end
Edited on 08 April 2014 - 01:37 AM
Lua.is.the.best #3
Posted 08 April 2014 - 10:48 PM
Added 6 lines "if not http", 2 lines (get and load the iterator as an API), and 5 lines (usage).
13 lines added :P/>
I owe you a 32e*924e(12481284182481284*23857239587239587) TB SSD!
xD just joking, but you really deserve 48 of the world's largest and fastest SSD :P/>
Edit: I deny that now.. It errored on line 8..
Also a file not found..
Edit: Aha, probably because I loaded it as an API :o/>
Edited on 08 April 2014 - 08:55 PM
theoriginalbit #4
Posted 09 April 2014 - 01:35 AM
oh oops, sorry, was so long ago I forgot, you'd do this

for fullpath,file in fileSystemIter() do
  if file:lower() == "newapi" then
	os.loadAPI( fullpath )
  end
end

the first variable returned is the full path including filename. the second is the filename so you can easily check.
Edited on 08 April 2014 - 11:43 PM