Lua Libraries.

Go down

Lua Libraries.

Post by JHaskly on Sat Oct 23, 2010 11:24 pm

Lua Libraries are a very helpful thing. They allow you to store functions, values, whatever you want, in files so that you don't have to write them in every model you make.

For example, the limit function:
function limit(val,min,max)
    return math.min(math.max(val,min),max)
I use this function in almost all of my models, so it's in my library.

Some members, (bwansy and I), have our Lua libraries up on the forums. Most models we release require our libraries, so you need them to use the models.
Most Lua libraries will come in .zip files, because they can be multi-filed. So, to install them, just extract the files, and make sure they are in the proper file path. I.e: Most people will supply a filepath when they release their libraries (mine is "Juz\<FILES>").See General Practice 1. And violĂ !

Using libraries is very simple. At the top line of your Lua code, place:
require("<FILE PATH\FILE>")
Repeat this for every file you need. Now you can just use the variables and functions normally.

Creating libraries is very simple. Put all of the things you want in the file, and save it in the file path you want.See General Practice 2.

General Practice:
  1. When releasing libraries, name the file path as either your name, or "Lua\<NAME>".
  2. Try and save the file as a *.lua file (you can save it as something else, but try not to).
  3. If your library has a lot of files, create a single file that requires all the others by itself (Mine is index.lua). Then you only have to require one file!
  4. If you have a library for something very specific, like drawing lines on the screen, then you can store all of those functions inside a table, to keep them organised.

Previously (and currently) known as Juz.

Please do not write "LUA", beause it's "Lua". It's Moon in Portuguese, not a Limited User Account, Last Universal Ancestor, or the Lukla Airport in Nepal.


Posts : 235
Join date : 2010-07-16
Age : 23
Location : Brisbane

View user profile

Back to top Go down

Re: Lua Libraries.

Post by MrSparks on Tue Jan 17, 2012 2:53 pm

What about setting the file path so RC knows where to look? I want to say there was a .bat involved.


Posts : 73
Join date : 2012-01-05
Age : 28
Location : Michigan

View user profile

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum