External dependencies
This guide will be about adding and handling external Java libraries from http://mvnrepository.com and external Lua dependencies from http://luarocks.org.
To add Java library dependency to your project, we will use our awesome project.yml
. In this guide we will be adding Apache Commons IO Java dependency and luaassert Lua dependency.
libs:
- commons-io:commons-io:2.4
As you can see, library names are delimited by :
. First bit is dependency maintainer, second is dependency name and last one is dependency version.
rocks:
- luassert
Lua dependencies are called rocks
and including them is super simple as you can see above.
Now, try to start your project. Message stating that engine is downloading commons-io:commons-io:2.4
and installing luaassert
should appear. Your project should succesfully start. You do not see anything new? That´s fine.
We will use java
module to load some dependency code. We will try to use Commons IO to get us available storage space on our drive. So, let´s go.
import java from yae
FileSystemUtils = java.require "org.apache.commons.io.FileSystemUtils"
yae.ready = ->
freeSpace = FileSystemUtils\freeSpaceKb!
print freeSpace
To use them, we will use built-in require function:
assert = require "luassert"
assert.True true
assert.is.True true
assert.is_true true
assert.is_not.True false
assert.is.Not.True false
assert.is_not_true false
assert.are.equal 1, 1
assert.has.errors ->
error "this should fail"
NOTE: Some tutorials are edits of LibGDX tutorials, what can be found here.