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

[LUA] alternative for require

Started by dvdbrander, 26 June 2012 - 09:27 PM
dvdbrander #1
Posted 26 June 2012 - 11:27 PM
Hello
I have got a file named goto with in it a function goto(x,y,z), that works on a gps. Now do I want to use that function from another file. So I searched for lua, and came up with require "goto". Require seems to be removed from CC, so I tried several alternatives like assert(loadfile()) and so, but none of them seems to work. I also tried to use os.loadAPI as a workaround, but then the gps system doesn't seem to work (in goto). What should I use and how should I use it?
MysticT #2
Posted 26 June 2012 - 11:31 PM
You have to use os.loadAPI. The only default api that you can't use in another api is shell, since it's not really loaded as an api, but the gps api should work. If it doesn't, post the error (if there's one).
kazagistar #3
Posted 27 June 2012 - 03:11 PM
I never use loadapi, I prefer shell.run(). But I am also very disciplined about global namespace usage, so it might not be the right choice for everyone.