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

require() AMD for CC... an API to include APIs?!

Started by comp500, 19 February 2015 - 08:08 AM
comp500 #1
Posted 19 February 2015 - 09:08 AM
require()
This is a utility function that will make working with APIs so much easier. It doesn't replace os.loadAPI(), it enhances it. You can include many APIs at once, and they are stored in a local variable, reducing conflicts:

module1, module2, module3... = require(location1, location2, location3...)
It is only around 600B when minified and can be inserted at the top of your programs. It searches for APIs, so you don't have to specify exactly where they are. If you require an absolute path (with a trailing slash), require will look just in that directory. If you require a relative path (no trailing slash), require will search in the current directory and all directories above it, for example:

-- /superstuff/awesome/lol
module1 = require("superapi")
module1.test()
-- /superapi
function test()
print("this is super")
end
require() would search:
/superstuff/awesome/superapi
/superstuff/superapi
/superapi

Another great feature is that it works with every api that works with os.loadAPI, whch means you don't need to change apis or ask the author to change them. The way they are stored in a local variable makes it even easier to use the touchpoint API:

t = require("touchpoint").new()
t:add(...)
t:draw()

Want it? To see more information and where to download it, see the https://github.com/comp500/CCSnippets for the github repository.
If you don't care about github and just want a download, minified versions are available in the releases: https://github.com/c...ippets/releases
My utilities are under the MIT license, so feel free to fork and send pull requests on the CCSnippets repository, but don't remove the license and give credit.

Please note that ComputerCraft 1.63 is required, see the github readme for more details.

To-Do list:
  • Add support for some sort of lib/ directory
Edited on 20 February 2015 - 06:49 AM
comp500 #2
Posted 21 February 2015 - 08:19 PM
ok…. im taking it nobody wants this….
MKlegoman357 #3
Posted 21 February 2015 - 10:03 PM
Or, nobody has any comments on your function. Don't take it as 'nobody likes it', it's just how things usually work with good APIs, programs and utilities here. Nobody said anything because there isn't anything bad about your function, which is good. Also, there are no suggestion which means that there is nothing to suggest as there is everything here already. I see this as a very nice and simple function to load APIs and I think it is quite good. There are some quality-products here on the forums and you'll find that they also don't have that many replies. I believe it's just because of the audience here on CC forums. Anyway, don't stop on making these kind of things and posting them on the forums. I'm sure they will help you someday, and I'm not talking about just programming ;)/>.

Keep up the good work! :)/>
Edited on 21 February 2015 - 09:05 PM
comp500 #4
Posted 22 February 2015 - 07:21 AM
Or, nobody has any comments on your function. Don't take it as 'nobody likes it', it's just how things usually work with good APIs, programs and utilities here. Nobody said anything because there isn't anything bad about your function, which is good. Also, there are no suggestion which means that there is nothing to suggest as there is everything here already. I see this as a very nice and simple function to load APIs and I think it is quite good. There are some quality-products here on the forums and you'll find that they also don't have that many replies. I believe it's just because of the audience here on CC forums. Anyway, don't stop on making these kind of things and posting them on the forums. I'm sure they will help you someday, and I'm not talking about just programming ;)/>.

Keep up the good work! :)/>
Thanks! I found that my github traffic has a steady flow of visitors :D/>
Creator #5
Posted 24 April 2015 - 04:15 PM
How do you minify the code?
Lignum #6
Posted 24 April 2015 - 04:36 PM
How do you minify the code?

Tools like luamin can do this. Here's an online minifier that uses luamin as its backend.
comp500 #7
Posted 25 April 2015 - 07:01 AM
How do you minify the code?

Tools like luamin can do this. Here's an online minifier that uses luamin as its backend.
Yup. I used to use LuaMinify (by stravant on github), but I found out luamin actually minifies much better than LuaMinify.
SquidDev #8
Posted 25 April 2015 - 09:04 AM
Yup. I used to use LuaMinify (by stravant on github), but I found out luamin actually minifies much better than LuaMinify.

Hmmm, strange - I always found that luamin broke my code when I minified with it. LuaMinify works perfectly - the main issue is that it generates massive variable names, though you can change that.