RigidChips
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Lua Libraries.

2 posters

Go down

Lua Libraries. Empty Lua Libraries.

Post by JHaskly 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:
Code:
function limit(val,min,max)
    return math.min(math.max(val,min),max)
end
I use this function in almost all of my models, so it's in my library.

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

Creating:
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.

JHaskly
Admin

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

Back to top Go down

Lua Libraries. Empty Re: Lua Libraries.

Post by MrSparks 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.

MrSparks
Tank
Tank

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

Back to top Go down

Back to top


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