Jump to content




os.loadAPI( name )


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

#1 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 13 March 2013 - 09:30 AM

Hi there, the other the day I was thinking about this topic and now I have some questionmarks.

First of all I went of course to the wiki ( doesn't do everyone that? ):
os.loadAPI( name )
Loads a Lua script as an API in it's own namespace (see example). It will be available to all programs that run on the terminal.

So note the variable must be name not path. So let's say we are in the same folder as the API then we use:
os.loadAPI( "myfunction" )

print( myfunction.printsomething() )

os.unloadAPI( "myfunction" )

And if I am not in the same folder, how would I use it then?
I think this is wrong:
os.loadAPI( "somedir/myfunction" )

print( somedir/myfunction.printsomething() ) -- This is where it confuses me

os.unloadAPI( "somedir/myfunctions" )

So if you guys can help me with this, that would be very appreciated :)

Thanks, Engineer

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 13 March 2013 - 09:45 AM

In bios.lua:

function os.loadAPI( _sPath )
	local sName = fs.getName( _sPath )
	...

So no, it'd be myfunction either way.

#3 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 13 March 2013 - 09:54 AM

View PostLBPHacker, on 13 March 2013 - 09:45 AM, said:

In bios.lua:

function os.loadAPI( _sPath )
	local sName = fs.getName( _sPath )
	...

So no, it'd be myfunction either way.

Thank you! They really should change it in the wiki to path if you ask me. Just to prevent confusion, or a better description will do. Maybe my English isn't good enough to understand it quite but these are my thoughts.

Thanks again :)

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 13 March 2013 - 10:03 AM

You have to pass the full path to the api file as the argument, since it doesn't use the shell directory. It will use only the file name as the api name, so you can put it in any folder and it should work.

#5 JokerRH

  • Members
  • 147 posts

Posted 13 March 2013 - 10:15 AM

os.loadAPI("path/name")
os.unloadAPI("name")
(As far as I remember...) loadAPI will use loadfile to load the api (so you need the path for it to find the right file) and inserts it into the global envirment as the last component of the path, the name.
unloadAPI will delete the index in the global enviroment and because the index was set to the name by loadAPI unloadAPI only needs the name.

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 13 March 2013 - 11:17 AM

View PostJokerRH, on 13 March 2013 - 10:15 AM, said:

(As far as I remember...) loadAPI will use loadfile to load the api
Nope its more than just a loadfile, its actually functionally closer to dofile.
From bios.lua
Spoiler


#7 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 13 March 2013 - 11:51 AM

View PostTheOriginalBIT, on 13 March 2013 - 11:17 AM, said:

View PostJokerRH, on 13 March 2013 - 10:15 AM, said:

(As far as I remember...) loadAPI will use loadfile to load the api
Nope its more than just a loadfile, its actually functionally closer to dofile.
From bios.lua
Spoiler
He ment that it uses loadfile (and it does), and loadfile needs a full path, so os.loadAPI also needs it.

#8 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 13 March 2013 - 12:11 PM

Thanks for clearifying that up. All I need to know if I needed to be in the same folder ^^

Thanks though :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users