Sign in to follow this  
Valen III

#include functionality for Lua

Recommended Posts

Valen III    122
I'm trying to adapt our current scripting system to allow for "includes" of common scripts so they may be reused. Currently, we load all scripts on a per level basis, and each level has its individual scripts plus one common file. What we want to do is have more then one common file, but as opposed to loading them all for all levels, we want the ability to pick and choose which common scripts load. We've had two ideas so far. One is to have a table inside our main level script that identifies all the resources we need... however, the problem here lies in first that not all levels have a level script, and additionally the load order is currently alphabetical, meaning our level script would load long after anything before an L. Another idea was to have a particular script just for declaring scripts to include. This would require we make sure the include script is ALWAYS loaded first, but this method would also add a new script file to every level. Does anyone know of any other methods, or if one of the two above would be the best way to do things?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I may be missing something but wouldn't 'dofile' (or better 'loadfile') work?

Share this post


Link to post
Share on other sites
Valen III    122
loadfile doesn't address our concerns very well as it doesn't automatically check if a script has already been loaded or not. I've had a friend suggest using Verify , but I haven't had much time to investigate modules. As of now, we only have stand alone scripts.

Share this post


Link to post
Share on other sites
Vorpy    869
Just use Lua's modules system.

In your module named modulename.lua you start with a line like:
module(...)

and to load the module you use:
require(modulename)

modulename.somefunction(blahblahblah)

The modules work by doing stuff with tables. You could also write your own module system.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this