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.
Help using libraries
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Help using libraries
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.
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.
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
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' )
Code: Select all
local module = require ( 'module.submodule' )
Who is online
Users browsing this forum: Google [Bot] and 5 guests