Hard Light Productions Forums

FreeSpace Releases => Scripting Releases => Topic started by: m!m on November 24, 2014, 03:23:38 pm

Title: Lua Utilities library
Post by: m!m on November 24, 2014, 03:23:38 pm
I put together a small lua package that contains a few things that could be useful for a lua coder: https://github.com/asarium/FSOLuaUtils

Contents:
require package loader
The package contains a loader implementation so you can use require (http://www.lua.org/manual/5.1/manual.html#pdf-require) with modules that exist within the file system of FSO (that also includes VP files).
There is not much more to know about it except that when the loader has been initialized the variable cfileRequireInitialized is set to true. You can use that to delay the usage of require until the loaders have been initialized.

Coroutine manager
You can now use coroutines within FSO to execute code distributed over multiple frames (if you don't know what coroutines are you can read this tutorial (http://www.lua.org/pil/9.1.html)).
To use coroutines you first have to require the 'fsoCoroutine' module (fsoCoroutine = require("fsoCoroutine")).
The currently available function in that module are:

Example:
Code: [Select]
local fc = require("fsoCoroutine")
fc.startCoroutine(function()
doSomeStartingStuff()

fc.waitUntil(fc.secondsPassed(10))

doSomeStuff()

fc.waitUntil(fc.secondsPassed(20))

doSomeOtherStuff()
end)
Title: Re: Lua Utilities library
Post by: niffiwan on November 24, 2014, 04:17:59 pm
Sounds pretty cool!  :yes:
Title: Re: Lua Utilities library
Post by: Nuke on November 24, 2014, 05:25:33 pm
this is very useful. now you can write stand alone scripts and let everyone require them in their own code.

i guess it would be good practice to put binary module files for all platforms into your file structure/vp files. it should in theory work the same on linux as windows after that.
Title: Re: Lua Utilities library
Post by: m!m on November 25, 2014, 05:29:37 am
I created a Github repository with the code for easier version management.
I changed the loaded to also try loading .lc files if the modder distributed a precompiled version of the module.