Help using libraries

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
shelteredstare
Prole
Posts: 1
Joined: Sun Aug 20, 2017 4:09 pm

Help using libraries

Post by shelteredstare »

I'm fairly new with Lua, and I seem to be having issues using libraries such as those listed on the Lua wiki. I understand that I need to include
the files in the same folder as my main.lua, but I'm not having much luck after that. I'm sure it has nothing to do with luck so I'd appreciate a nudge in the right direction.

1. relocate files into the same folder as my main.lua
2. ??? I have not a clue what to do after that...

I'd love to figure out some of these libraries, especially GUI specific libraries, but I just can't seem to wrap my head around
the implementation.

Any help is appreciated, thanks.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Help using libraries

Post by raidho36 »

First of all, modules are loaded by module name, not file path. This is very important to grasp immediately, it'll save you a ton of trouble later on. Attempting to load module by file path will fail to work.

You load a module by using the "require" function, and you pass the module name into it. If the module returns anything, it will be returned from the require function. Some modules can set global variables. Most of them however will return a table which you are supposed to use to access the module functionality.

Code: Select all

local module = require ( 'module' )
There are a few default locations for modules, require function will look for modules in there. One of them is in the same directory as your game. You can override this with the "setRequirePath" function. A module can contain sub-modules, and if so it comes as a directory with files in it. You then access specific sub-module using dot notation.

Code: Select all

local module = require ( 'module.submodule' )
inb4 some smartass will post some of the missing information that will make people fall into the very pitfalls i've been trying to ward them off of by not posting all that
Post Reply

Who is online

Users browsing this forum: Google [Bot], Roland Chastain and 215 guests