Quick Lua Question
Displaying 1-4 of 4 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Code

Hi!
Is there a preprocessor command in LuaVerge that acts just like #include "blargh.vc" in VC? Or will I have to make a bona fide module and then say require "blargh"?

Posted on 2009-01-06 21:27:45

Overkill

Lua doesn't have preprocessor statements. Including files is done at runtime!

You don't need to create a module or anything (though you can!). To include another file (for example "blargh.lua"), just do this:
require "blargh"
If you actually want to package together files, you can create a folder named like "mypackage", and put a Lua file named "init.lua" inside, which will do the loading of all the crap. Then you just require the entire package like this (which will load the init.lua in that folder)
require "mypackage"
If for some reason you need to change the way files are included, check out package.path.

Stupid example, but say you want to include files that are like AwesomeNachos, AwesomeHats, AwesomePants with a simple require like this:
require "Nachos"
require "Hats"
require "Pants"
To allow this, you can modify the load path.
package.path = package.path .. ";Awesome?.lua"
So you are able to add rules which will change how files are included. Each entry is separated by ; semicolon. Question marks ? represent "wildcards", which are whatever the text provided to require happens to be.

Though this is really more useful for requiring files in subfolders or something, but same rules.

Posted on 2009-01-06 22:31:48 (last edited on 2009-01-06 22:47:21)

Code

Awesome Nachos! Thanks for clearing that up!

Mind if I just copy and paste that into your Learn Lua wiki?

Posted on 2009-01-06 23:10:24

Overkill

Go ahead. Just make sure to put in a header for the section and we're all good.

Posted on 2009-01-06 23:51:57 (last edited on 2009-01-06 23:52:29)


Displaying 1-4 of 4 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.